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 6223219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:27:02+00:00 2026-05-24T08:27:02+00:00

I made a number of html forms containing only radio buttons and a submit

  • 0

I made a number of html forms containing only radio buttons and a submit button. However, I cannot get them to validate properly–independently of each other. Here is my code:

PHP/HTML code for the form:

<table>
<?php
for($i=0; $i<count($array1); $i++)
{
  $number = $i + 1;
  echo "<TR><TD>;
  echo "<form name='move' action='listChange_controller.php' method='POST'>Title:<br/>
        <input type='radio' name='change".$number."' value = 'val1' />Thing1
        <input type='radio' name='change".$number."' value = 'val2'/>Thing2
        <input type='radio' name='change".$number."' value = 'val3'/>Thing3
        <input type='button' name='submit' value='submit' onClick='validate(".$number.");'/>";
  echo "</form>";
  echo "</TD></TR>";
}
?>
</table>

Here is the javascript/jquery I have been trying, but has not worked:

function validate(number)
{
    var name_var = 'change'+number;
    if($('input:radio[name=name_var]:checked').length > 0)
    {
        $.post('file.php',{ name_var:$('input:radio[name=name_var]:checked').val()});
    }
    else
    {
       alert('You must choose');
       return false; 
    }
}

When I do this, it always thinks I have not chosen a radio button before pressing submit; it always carries out the ‘else’ part of my javascript function.

Please let me know why it is not working, and what would work. Any help and suggestions appreciated.

  • 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-05-24T08:27:03+00:00Added an answer on May 24, 2026 at 8:27 am

    This line…

    if($('input:radio[name=name_var]:checked').length > 0)
    

    should read

    if($('input:radio[name=' + name_var + ']:checked').length > 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a number of very old data entry forms that were made in
Context: .Net, C# I want to print a complex number made from two doubles.
I have an array made of unlimited number of objects. These objects have the
This is a C++ class that I have made with n number of pointers.
I made a datatype of type number that can be either an int or
How do I calculate number of years since product was made (rounded to 1
I have made a phone bill system takes input of phone number called, date
The linq collection is made of a SearchResult object. SearchResult contains: id (number), categoryName
Is there any query which can return me the number of revisions made to
i have a container box that includes a number of thumbnails. i earlier made

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.