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
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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.