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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:58:03+00:00 2026-05-15T05:58:03+00:00

I have a list of select boxes with incremental numbers to identify then e.g.

  • 0

I have a list of select boxes with incremental numbers to identify then e.g.

<select id="my-select-0">
  <option value="1">first option</option>
  <option value="2">first option</option>
< option value="3">first option</option>
</select>
<select id="my-select-1">
  <option value="1">first option</option>
  <option value="2">first option</option>
  <option value="3">first option</option>
</select>
<select id="my-select-2">
  <option value="1">first option</option>
  <option value="2">first option</option>
  <option value="3">first option</option>
</select>

I have a json string which I want to use to pre populate these selects e.g.

json = "[{'my-select': 1}, 
         {'my-select': 3}]";

in the example above my-select-0 would be set to 1 and my-select-1 is set to 3.

How would I go about doing this in JQuery?

Thanks

  • 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-15T05:58:03+00:00Added an answer on May 15, 2026 at 5:58 am

    I’m not sure exactly what you’re after, but if you change the JSON to be valid (double quotes) you can do it using $.parseJSON() and looping through, like this:

    var json = '[{"my-select": 1}, {"my-select": 3}]';​​​​​​​​​
    
    var selects = $("[id^=my-select]"); //a class maybe? not sure of your options
    $.each($.parseJSON(json), function(i, v) {
        selects.eq(i).val(v['my-select']);
    });
    ​
    

    You can see a working demo here


    Update: Since you control how this is rendered in the page just remove the initial quotes it’s wrapped in, like this:

    var json = [{'my-select': 1}, {'my-select': 3}];
    var selects = $("[id^=my-select]");
    $.each(json, function(i, v) {
        selects.eq(i).val(v['my-select']);
    });
    

    You can see it working here, JSON is exactly what it’s name says, object notation…so just use it that way, don’t make it a string, just output/declare it directly as a javascript object…in this case it’s an array you can loop through, and it’s of course faster without all that extra work.

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

Sidebar

Related Questions

I have a list like this: <select name=select_list_name id=list_id> <option value=>Select Option</option> <option value=value1>Option
I have a page with a list of almost identical select boxes. I want
I have a select list which is being populated using the values from a
i have list of rows that user select and i want to delete them,
I have a list in a select. After selecting an option i do a
I have a html form which have a select list box from which you
I have a multi-select list box. I want to be able to select a
I have the following select list from which the user can select multiple values.
I have such select list in html: <input type=checkbox name=drive_style value=1 checked />123<br />
i have a set of radio boxes, and a select list. The radio boxes

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.