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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:46:03+00:00 2026-05-26T01:46:03+00:00

Why do php form input arrays act funny in jQuery? Is there any way

  • 0

Why do php form input arrays act funny in jQuery?

Is there any way to overcome this?

Hi, I wrote this code and it works..
Updating a form of 21 radio inputs to emphasize the label next to the checked radio(s).

*visually – not as in the a html tag

$(function()
{       
for(count = 0;count<21;count++)
{
    result = $("input:radio[name=choice"+count+"]:checked").val();
    $("input[name=\"choice"+count+"\"][ value=\""+ result +"\"]").attr("class", "magic");
    $("div.radio:has(input.magic)").attr("class", "radio spell");   
}
$("input").click(function()
{
    $("div.radio:has(input.magic)").attr("class", "radio");
    $("input.magic").removeAttr("class", "magic");

    var count = 0;
    var result = 0;
    for(count = 0;count<21;count++)
    {
        result = $("input:radio[name=choice"+count+"]:checked").val();
        $("input[name=\"choice"+count+"\"][ value=\""+ result +"\"]").attr("class", "magic");
        $("div.radio:has(input.magic)").attr("class", "radio spell");   
    }
});
});

Here is the css

input[type="radio"] {
height: 20px;
}

input[type="radio"] + label {
color: #777;
font-weight:100;
letter-spacing: 1px;
}

input[type="radio"].magic + label {
color: black;
font-style: italic;
/*text-decoration:underline;*/
font-weight: 600;
letter-spacing: 0px;
text-align: center;
display:inline-block;
width: 80px;
}

div.radio.spell {
border: outset white 2px;
}

Now the radio names used are choice0 – choice20
And it works ok.

Before that I used choice[0] – choice[20]
And it did not work at all.
It behaved very weird.

The jQuery code was something like:
result = $(“input:radio[name=choice[“+count+”]]:checked”).val(); …

I am wondering, is there anyway around that?

Thank you for any valuable input.

  • 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-26T01:46:03+00:00Added an answer on May 26, 2026 at 1:46 am

    [ and ] are used for attribute selectors in jQuery, you need to escape them to use them as part of a string: $(":radio[name=choice\["+count+"\]]").

    That said, this is a rather uncomfortable way of manipulating element groups. The easy way is to create a HTML structure which reflects those groups, and use that to find other members of a group:

    $(function() {
        $(":radio[name^=choice]:checked").each(function() {
            $(this).closest('div.radio').attr("class", "radio spell")
                .find("input[name^=choice]").attr("class", "magic");
        });
    });
    

    etc.

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

Sidebar

Related Questions

I got this code in my submit form <form id=myform action='hello.php' method='GET'> <input type=button
i have done something like this: <form action=validate.php method=get> Id :<input type=text name=pID/><br/><br/> Name
I have code that looks like the following: <form id=MyForm name=MyForm method=post action=index.php> <input
I've seen a lot of PHP code that handles form input in which the
I have a complex input form within a PHP based web application. To structure
Example to save gender <form action=save.php?id=<?=$id?> method=post> <p><label><input name=gender type=radio value=male <?php if($gender=='male'){?>checked=checked<? }?>
According to php manual nor php://input neither $HTTP_RAW_POST_DATA work with multipart/form-data POST-requests. php://input allows
I have a php file that contains a form (which contains 2 input boxes
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have an HTML form: <form action='process.php' method='post'> <input type='checkbox' name='check_box_1' /> Check me!<br>

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.