javascript - function not working in jsp page? -


<script> function keepcount() {      var x=0;     var count=0;     var x;             for(x=0; x<document.questiongenerate.elements["questions"].length; x++){              if(document.questiongenerate.elements["questions"][x].checked==true || document.questiongenerate.elements["option"][x].checked==true || document.questiongenerate.elements["description"][x].checked==true || document.questiongenerate.elements["fillups"][x].checked==true){                     count= count+1;                    document.getelementsbyname("t1")[0].value=count;                     }                 else                     {                       document.getelementsbyname("t1")[0].value=count;                       //var vn=$('#t1').val();                    // alert(vn);                      //alert(vn);                       //alert("value is"+count);                     }             }             // var cc = document.getelementsbyname("t1")[0].value;              var vn=$('#t1').val();             alert(vn);              if(vn==0){                 alert("you must choose @ least 1");                return false;             }         }     </script>  <form action="selectedquestions.jsp" method="post" name="questiongenerate">      <input type="text" name="t1" id="t1" value=""> <input type="submit" id="fi" name="s" value="finish" onclick="return keepcount();"> </form> 

i use above code checking how many check box checked in form form having many check box. , if no check box selected means shows message , submit form loop working , textbox value after loop bellow code doesn't work alert() not working

**

var vn=$('#t1').val();                 alert(vn);                  if(vn==0){                     alert("you must choose @ least 1");                    return false;                 } 

this code not working why?

**

i change keepcount() function code shown in bellow solve problem

 function keepcount()   {             var check=$("input:checkbox:checked").length;           alert(check);            if(check==0)               {               alert("you must choose @ least 1");               }     return false;    } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -