javascript - if statement is not identifying the condition stored in variable -
i having jsp page in asking few multiple choice questions. using radio buttons display options.
now want write javascript function putting mandatory check fields. code this.
var lengh = document.getelementbyid("totalques").value; for(i=1; <= lengh; i++){ var radioname= "radio"+i; var radioques = document.getelementsbyname(radioname); var concats= ""; for(j=0; j< radioques.length; j++){ concats = concats+"(radioques["+j+"].checked == false)"; concats= concats + " && "; } var sliced= concats.slice(0, concats.lastindexof("&&")); if(sliced){ msgid="question "+i; id="radio"+i; check=false; break; } if(check==false){ alert("kopkopok break part"); } }
the problem lies in
var sliced= concats.slice(0, concats.lastindexof("&&")); if(sliced){ msgid="question "+i; id="radio"+i; check=false; break; }
my if statement not identifying condition have stored in sliced variable. please help....
it looks you're trying evaluate string
"(radioques[1].checked == false) && (radioques[2].checked == false) ..."
and see if condition described true. comparing string false
won't that. better check buttons loop through them, looking 1 that's checked. if none found, show alert:
var lengh = document.getelementbyid("totalques").value; (i = 1; <= lengh; i++) { var radioname = "radio" + i; var radioques = document.getelementsbyname(radioname); var = false; (j = 0; j < radioques.length; j++) { if (radioques[j].checked) { = true; break; } } if (!any) { msgid = "question " + i; id = "radio" + i; alert("kopkopok break part"); break; } }
Comments
Post a Comment