Jump to content

Radio button validation


jeeva

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/41411-radio-button-validation/
Share on other sites

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?

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.