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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:06:47+00:00 2026-05-25T12:06:47+00:00

I have a form with a select element that contains a list of categories

  • 0

I have a form with a select element that contains a list of categories populated from an external source. When I submit the form I want to be able to post parameters for the value for the option selected (category_id), this works as expected. However I also want to pass a second parameter (category_name) which is currently the text of the select option.

For the sake of clarity below is a very simple representation of the select element:

<select name="category_id" id="category_id">
<option value='1'>All</option>
    <option value='2'>Category 1</option>
    <option value='3'>Category 2</option>
</select> 

I was wondering what the best way of doing this is. Do I need to use Javascript or is there some way of doing this via HTML? For what its worth Im using Rails to build the app so if there is a smart way to do this using the framework that would also be very useful to know.

Thanks in advance for the help.

Dave

  • 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-25T12:06:47+00:00Added an answer on May 25, 2026 at 12:06 pm

    You could either change the value so it contains both values then just split them on the server:

    <select name="category_id" id="category_id">
        <option value='1|All'>All</option>
        <option value='2|Category 1'>Category 1</option>
        <option value='3|Category 2'>Category 2</option>
    </select> 
    

    Or use some javascript and update a hidden field:

    HTML

    <select name="category_id" id="category_id">
        <option value='1'>All</option>
        <option value='2'>Category 1</option>
        <option value='3'>Category 2</option>
    </select> 
    <input type="hidden" id="category_name" name="category_name" />
    

    JS

    function updateNameValue() {
        $('#category_name').val($('#category_id option:selected').text());
    }
    
    $('#category_id').change(updateNameValue);
    
    updateNameValue(); // Call function here to make sure initial value is set
    

    http://jsfiddle.net/6runZ/

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

Sidebar

Related Questions

I have an javascript object that contains a select list. I'd like to loop
I have the following select form element, and I want to apply the rateit
I have an HTML select form that populates my list with elements found in
I have a simple select element that I want to set the value for
I have a select form element with 5 options. If option 2 is selected
The select form component in grails can have the form: <g:select name=user.age from=${0..59} value=${age}
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
i have a form that has a multiple select drop down. a user can
I have a form where a subscriber can select the newsletters they want to
I have a list of type A, in which each element contains another list

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.