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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:56:15+00:00 2026-06-06T05:56:15+00:00

I have a rather complicated lookup for an option. It comes from a separate

  • 0

I have a rather complicated lookup for an option. It comes from a separate system and I really need to keep track of two pieces of data instead of sending only one and having to do additional lookups which are expensive. Ideally, I want to pass all the data I received from one AJAX call into another.

Standard stuff:

<select name="chosen_option" id="chosen_option">
  <option value="apple">Option One</option>
</select>

Accessing it with javascript is fairly simple:

$("#chosen_option).val()

I know I have many ways to put extra data into the option according to my searches:

<option value="PartA:'apple',PartB:'450'">Option One</option>
<option data-partb="450" value="apple">Option One</option>

For the first method I don’t understand how to reference PartA or Partb on their own, only the entire value for the option.

For the second method the selector is not capable of grabbing that particular attribute from the selected option. It says undefined.

Adding an ID to each individual option does not allow me to grab it either:

<option id="optionid_apple" data-partb="450" value="apple">Option One</option>

$("#optionid_apple").attr('data-partb)  // Not working
$("#optionid_apple").data('partb') // Not working
$("#optionid_apple").data('data-partb') // Not working

How can I store multiple pieces of data on a single option and access it in Javascript?

P.S – I thought about making the value itself an XML doc, but I don’t really know how to do that correctly in the HTML, etc.

  • 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-06T05:56:17+00:00Added an answer on June 6, 2026 at 5:56 am

    Use this to make sure that you get the selected option.

    $("#chosen_option option:selected").data('partb')
    

    otherwise you are trying to get attributes from the <select> tag.

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

Sidebar

Related Questions

I have a (rather complicated) SQL statement where I select data from lots of
I have a jqGrid (pared-down example below) where I need rather complicated validation to
I have a rather complicated scenario that I have never really had to deal
So i have this application thats rather complicated... To keep it short this is
We have a rather complicated system of permission handling in our (ASP.NET web) application.
I have a rather complicated setup with two columns full of elements. Clicking on
I have a rather complicated (and very inefficient) way of getting utilisation from a
I have a rather complicated deploy setup for our Drupal site that is a
I have the following tricky problem: I have implemented a (rather complicated) class which
I have a rather complicated toolchain so prepare for a lengthy post until getting

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.