Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我点击单选按钮时,我得到了jsp中未定义的消息。问题是什么?_Javascript_Jsp - Fatal编程技术网

Javascript 当我点击单选按钮时,我得到了jsp中未定义的消息。问题是什么?

Javascript 当我点击单选按钮时,我得到了jsp中未定义的消息。问题是什么?,javascript,jsp,Javascript,Jsp,单击单选按钮想要显示id值,但当我单击单选按钮时,它会显示未定义的消息。为什么会这样 <script language="javascript> function openSubrurbicPopup(){ alert(document.frmRubric.rubricid.value);} </script> <% try{ Class.forName("com.mysql.jdbc.Driver"); con = DriverMan

单击单选按钮想要显示id值,但当我单击单选按钮时,它会显示未定义的消息。为什么会这样

<script language="javascript>
function openSubrurbicPopup(){
 alert(document.frmRubric.rubricid.value);}
</script>
<% 
try{
     Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost/database", "root",   "admin");
        String sql = "select * from table where parentid='0'";
        rs = con.createStatement().executeQuery(sql);
    %>
        <form name="frmRubric" method="post" >
    <%  while(rs.next()){
            String id = rs.getString("id");
    %>
            <input type="radio" name="radio" onclick="openSubrurbicPopup()" />
            <input type="text" name="rubricid" value="<%=id%>" /><br>
        <%}%>
        </form>
    <%}catch(Exception e){
        out.println(e.getMessage());
        e.printStackTrace();
       }
    %>
</body></html>

首先需要检查单选按钮元素(DOM)是否已加载

如果单选按钮加载意味着,请尝试使用代码。当然这对你有帮助

var el = document.getElementsByTagName('input');

 if (document.forms['frmRubric'].el[i].type === 'radio' && document.forms['jobView'].el[i].name === 'radio')
 {
    if(document.forms['frmRubric'].el[i].checked == true )
    {
      alert( "val = " + document.forms['frmRubric'].el[i].value );
    }
 }else {
      alert('Element not loaded");
  }
}

就这样试试吧。在函数中传递文本框值

onclick="openSubrurbicPopup('<%=id%>');"

希望这对您有所帮助。

单击时没有发生任何事情。我也想知道。当我在标记前面添加一行并使用javascript打印它的值时,使用相同的方法只是通过更改字段名,然后它正确地显示值,而不是未定义的值。为什么会这样?不客气。你的投票/接受这个答案将使答案更有意义。
function openSubrurbicPopup(value){
       alert(value);
}