Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8770847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:38:28+00:00 2026-06-13T17:38:28+00:00

I have the following form: <form name=survey1 action=add5up.php method=post onsubmit=return validateForm()> <div id=question>Q1) My

  • 0

I have the following form:

<form name="survey1" action="add5up.php" method="post" onsubmit="return validateForm()">
<div id="question">Q1) My programme meets my expectations</div><br />
Always<INPUT  TYPE = 'Radio' Name ='q1'  value= 'a'> 
Usually<INPUT  TYPE = 'Radio' Name ='q1' value= 'b'> 
Rarely<INPUT  TYPE = 'Radio' Name ='q1' value= 'c'> 
Never<INPUT  TYPE = 'Radio' Name ='q1' value= 'd'> 
<input type="submit" value="addData" />
</form>

I am trying to validate whether a Radio button has been selected.

The code I am using:

<script type="text/javascript">
function validateForm()
{
if( document.forms["survey1"]["q1"].checked)
{
    return true;
}

else
{
    alert('Please answer all questions');
    return false;
}
}
</script>

This is not working. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:38:29+00:00Added an answer on June 13, 2026 at 5:38 pm

    When using radiobuttons you have to go through to check if any of them is checked, because javascript threats them as an array:

    <script type="text/javascript">
    function validateRadio (radios)
    {
        for (i = 0; i < radios.length; ++ i)
        {
            if (radios [i].checked) return true;
        }
        return false;
    }
    
    function validateForm()
    {
        if(validateRadio (document.forms["survey1"]["q1"]))
        {
            return true;
        }
        else
        {
            alert('Please answer all questions');
            return false;
        }
    }
    </script>
    

    Regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following form: <form name="quickAdd" action="" method="post" onsubmit="return quickAddProcess(this);"> <input type="hidden" name="quickAddFields[module]"
Lets say that you have a following simple application: <form action=helloServlet method=post> Give name:<input
I have the following form: <FORM action=http://url.to.mysite.com/doc.php method=post> <INPUT type=text id=name> <INPUT type=text id=id>
I have following form. <form action= method=post id=save-user> <button type=button name=save-user>Save</button> <button type=button name=save-user-close>Save
I have the following HTML form: <div id=main> <form Id=search-form action=/ViewRecord/AllRecord method=post> <div> <fieldset>
I have the following form <form id=myform method=post action=#> <div class=fields> <fieldset class=ui-widget ui-widget-content
I have the following form: <html> <body> <form action=upload_file.php method=post enctype=multipart/form-data> <label for=file>Filename:</label> <input
I have the following form: <form id=vintro-upload-form action={url}?nexturl={nextUrl} method=post enctype=multipart/form-data > <input name=file type=file/>
I have following HTML form <form action=https://sandbox.paypal.com/cgi-bin/webscr method=post id=paypalpost name=paypalpost> <input type=hidden name=rm value=2/>
I have the following form in cakephp: <div class=quickcontactDisplay> <?php echo $form->create('Enquiry',array('action'=>'add','class'=>'quickcontact')); echo $form->hidden('visitor_id',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.