jeeva Posted March 6, 2007 Share Posted March 6, 2007 hi frnds, i have a survey form.In that i need to validate the radio button.For that i have coded one javascript code but its not working properly. its keep telling the the alert message even if the answer are checked here that code function validate(formname) { for (var i = 1; i <= formname.numQtns.value; i++) { radioGroup = document.getElementById('Q' + i); if(!radioGroup.checked){ alert('Please answer all questions before submitting.'+i); return false; } } can u tell me wts the problem with this code? Quote Link to comment https://forums.phpfreaks.com/topic/41411-radio-button-validation/ Share on other sites More sharing options...
DanDaBeginner Posted March 6, 2007 Share Posted March 6, 2007 I guess the problem is if all the radio was not cheked then it will keep popping up.. maybe try to check the radio button if either is check not all... Quote Link to comment https://forums.phpfreaks.com/topic/41411-radio-button-validation/#findComment-200733 Share on other sites More sharing options...
KevinM1 Posted March 6, 2007 Share Posted March 6, 2007 hi frnds, i have a survey form.In that i need to validate the radio button.For that i have coded one javascript code but its not working properly. its keep telling the the alert message even if the answer are checked here that code function validate(formname) { for (var i = 1; i <= formname.numQtns.value; i++) { radioGroup = document.getElementById('Q' + i); if(!radioGroup.checked){ alert('Please answer all questions before submitting.'+i); return false; } } can u tell me wts the problem with this code? What's the code that calls the validate function? And what's the code after your 'return false' statement? Quote Link to comment https://forums.phpfreaks.com/topic/41411-radio-button-validation/#findComment-200959 Share on other sites More sharing options...
azaad Posted March 7, 2007 Share Posted March 7, 2007 function validate(formname) { for (var i = 1; i <= formname.numQtns.value; i++) { radioGroup = document.getElementById('Q' + i); } if(!radioGroup.checked) { alert('Please answer all questions before submitting.'+i); return false; } } place the false condition after the for loop.it will work. fenway: no e-mailing of code... keep it all in this thread. Quote Link to comment https://forums.phpfreaks.com/topic/41411-radio-button-validation/#findComment-201900 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.