robert_gsfame Posted March 21, 2010 Share Posted March 21, 2010 again problem with checkbox...i am really newbie at javascript so hope that anyone could help i have this function function check() { if((document.getElementById('id1').checked==false)&&(document.getElementById('id2').checked==false)){ alert('please check at least one checkbox');}else{ alert('Are you sure?');} if there are 2 records with id=id1 and id=id2 then no problem will occur, what if let assume no record for id1 or in other words Null?? i have tried the above code but not working Thx for your help! } Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted March 21, 2010 Author Share Posted March 21, 2010 i also tried this but not working function check() { var a=0; for(i==1;i<3;i++){ if(document.getElementbyId(i)!==null){ if(document.getElementbyId(i).checked==false){ a++;}}} if(a==0){ alert('Please choose at least one');}else{ alert('thx for choosing');} } Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted March 21, 2010 Author Share Posted March 21, 2010 function check() { var a=0; for(i=1;i<3;i++){ if(document.getElementById(i)!==null){ if(document.getElementById(i).checked==true){ a++; } } } if(a>0){ alert('You have chosen !');}else{ alert('Please choose one');} } This is the correct one!! got it!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.