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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:40:32+00:00 2026-05-30T19:40:32+00:00

I am populating a select field using JQuery on page load using this method

  • 0

I am populating a select field using JQuery on page load using this method

 $('#select').append('<option value="' + result + '">' + result + '</option>'); 

However this leaves the select box ‘blank’, i.e the first value in the options list is not preselected as the selected option.

How do I ‘refresh’ this list so that the first value is preselected?

  • 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-30T19:40:33+00:00Added an answer on May 30, 2026 at 7:40 pm

    You can add a “selected” attribute to the option element you’d like to be selected:

    $('#select')
        .append('<option value="' + result + '" selected="selected">' + result + '</option>'); 
    

    You don’t specify how you populate exactly you select element, using a loop, you could do like this:

    var data = ['a', 'b', 'c'];
    var $select = $('#select'); // you might wanna empty it first with .empty()
    
    for (var i = 0; i < data.length; i++) {
        var o = $('<option/>', { value: data[i] })
            .text(data[i])
            .prop('selected', i == 0);
        o.appendTo($select);
    }​
    

    DEMO


    So it seems you are using jQuery Mobile like you said in the comment.

    If you are using the selectmenu widget, you need to programmatically refresh after you make programmatic change to its content/structure:

    $select.selectmenu("refresh", true);
    

    Documentation

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

Sidebar

Related Questions

I am populating data using <select name=test> <option value='<%=session.getAttribute(tList)%>'><%=session.getAttribute(tList) %></option> </select> but the values
I'm using jquery validation, however a few particular field values can be copied from
I have been going through this tutorial on auto-populating boxes using jQuery and Ajax:
I have a standard select box which I'm populating using jquery by appending options,
I am using the jQuery 1.6.2. I am dynamically populating a select box using
I have an issue regarding to auto populating a select dropdown from jQuery/JSON data
I have a SELECT object and I'm populating it with AJAX(JQUERY). $(#setor).change(function(){ $(#loading).css(display, inline-block);
Related post: Populating a select box in a form using related ID in MVC3
Which is better from a security standpoint when populating an HTML select box? Option
I'm in process creating a form in Plone/PloneFormGen. This form has Multi-Select field that

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.