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

  • Home
  • SEARCH
  • 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 1017285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:40:46+00:00 2026-05-16T10:40:46+00:00

I have n number of select elements in an html page that are used

  • 0

I have n number of select elements in an html page that are used to allow the user to select categories.

All of the selected values need to get posted to the server with name attr values of category[] (this a restriction of the CMS I’m using), but as there are in fact multiple groups of categories from which the user must choose one each, when output as form elements the categories are split across multiple select elements like so:

<select name="category[]" id="price">         
   <option value="1">Under £30</option> 
   <option value="2">£30-50</option> 
   <option value="3">£50-100</option> 
</select>

<select name="category[]" id="colour">         
   <option value="4">Red</option> 
   <option value="5">Green</option> 
   <option value="6">Blue</option> 
</select>

So that users can easily see all of the options available in each group, I am dynamically replacing each of these selects with a group of radio buttons using jQuery 1.4. I can’t just insert them into the html as radio buttons because the identical name attr required by the CMS would then only allow one selection total when I want one per group.

The dynamically inserted radio buttons use the id attr value of the select that they were generated from as their name attr value, and have exactly the same values as the select options they are generated from.

Giving us generated html like this for each select/radio pair:

<input value="1" name="cat_price" type="radio"><label>Under £30</label>
<input value="2" name="cat_price" type="radio"><label>£30-50</label>
<input value="3" name="cat_price" type="radio"><label>£50-100</label>

<select name="category[]" id="price">         
   <option value="1">Under £30</option> 
   <option value="2">£30-50</option> 
   <option value="3">£50-100</option> 
</select>

The select element is then hidden dynamically so that only the radio group is visible.

What I want to do (and can’t quite work out) is for each select element, dynamically update the selected option whenever the checked value of the radio button with a name attr identical to the id of the select changes. ie so that when the radio inputs get changed to something like:

<input value="1" name="cat_price" type="radio"><label>Under £30</label>
<input value="2" name="cat_price" type="radio" checked="checked"><label>£30-50</label>
<input value="3" name="cat_price" type="radio"><label>£50-100</label>

my (hidden) select gets updated to:

<select name="category[]" id="price">
   <option value="1">Under £30</option> 
   <option value="2" selected="selected">£30-50</option> 
   <option value="3">£50-100</option> 
</select>

Which I can them post back to the server, preserving the original name attr and keeping all user choices across selects.

  • 1 1 Answer
  • 1 View
  • 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-16T10:40:46+00:00Added an answer on May 16, 2026 at 10:40 am

    Okay, figured out this wasn’t actually so tricky:

      $("input[type='radio']").change(function() {
        var name = $(this).attr('name');
        var value = $(this).attr('value');   
        //find the select with an id that matched the input name attr and the option within it with the same value.
        $("select[id=" + name + "] option[value=" + value + "]").attr('selected', 'selected');
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of CheckBox elements in my html page. What I want
Im trying to build a page that will allow a user to select a
I have the following query that retrieve the number of users per country; SELECT
Using xslt/xpath, I need to be able to select the two elements which have
I have a number of elements with the same class like this: <html> <head><title>example</title>
I have HTML page with following elements <img src='some link' id='_id_portlet1_1234' > link </img>
So I have a basic HTML <select> element where a user can select a
I have made a combobox for a web page. It takes values from user
I have a web page with 2 listboxes (HTML select control). The first listbox
i have a sql query where i count the number of rows SELECT count(*)

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.