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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:12:58+00:00 2026-06-13T23:12:58+00:00

I have a <select> form element where I create multiple <option> children based on

  • 0

I have a <select> form element where I create multiple <option> children based on looping through a jQuery array of objects.

I want to store each jQuery associated with an <option> on the <option> itself, I guess as a property. So that when I get the change event fired I can pull out the jQuery object which the <option> was based on.

I thought I could just set it using attr, serializing the object into JSON, but its not working. Any ideas?

Here is some code:

// creating the select: (data is a jquery array of objects)
    $(data).each(function() {
        var opt = $('<option></option>').val(this[id_property]).html(this[label_property]);
        // preserve the original jquery object on this <option> element:
        opt.attr('json', JSON.stringify(this));
        $(select).append(opt);
    });

// bind the onchange event, and try to recreate that original jquery object
    $(select).bind('change', function(event) {
        // this gives me a ref to the <option> element:
        var val = $(select).find(":selected");
        // now how to get the original jquery object?
        var item = $(val).attr('json');        
    });

I want that last line setting var item to the original jquery object – or somehow recreate it. I even tried doing an eval() passing in item since it is JSON formatted but it throws an error.

  • 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-13T23:12:58+00:00Added an answer on June 13, 2026 at 11:12 pm

    You can take advantage of the data() method in jQuery, this will likely yield you the most favorable results as well as giving you the ability to avoid unnecessary custom serialization.

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

Sidebar

Related Questions

I have a select form element with 5 options. If option 2 is selected
I want to create a JavaScript/jQuery/jQuery UI drop-down select for element ordering in my
I have a form with elements like: <div class=row1> <select name=someSelectField multiple=multiple class=selectList> <option
Here is a form element I have. <select id=state name=state style=width: 212px;> <option value=nsw>New
I have a form with 3 select elements. Each one, by default, has option
I have some problems sending an id though jquery. I have a form select
I have this select input in my form that I want to access via
In one of my current projects I have a dropdown (select) form element. I
I am attempting to have mechanize select a form from a page, but the
The select form component in grails can have the form: <g:select name=user.age from=${0..59} value=${age}

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.