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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:12:04+00:00 2026-06-19T00:12:04+00:00

Select2 loads all items from my list successful, the issue I found when try

  • 0

Select2 loads all items from my list successful, the issue I found when try to select a specific value when page loads. Example:

:: put select2 in a specific html element, no value is selected even all items are loaded.

$('#my_id').select2();

:: When the page is loaded I’m trying to show a specific item selected, but doesn’t work as expected, because even selected, the select2 doesn’t show it.

$('#my_id').val('3'); //select the right option, but doesn't render it on page loads.

How to make a selected option to pop up when pages loads?

Thanks in advance.

#UPDATED

:: How I load all select2 items (sorry, its jade, not pure HTML):

label(for='category') Category
    span.required *
select(id='category', style='width:230px', name='category')
    option(value='') - Select -
    each cat in categories
        option(value='#{cat.id}') #{cat.description}

P.S.: All items from my list are loaded.

:: How I initialize the select2:

Just put the following line code on my javascript and it does successful:

$('#category').select2();

:: How I’m trying to select a specific value:

  • First attempt:

      $('#category').select2(
          {
              initSelection: function(element, callback) {
                  callback($('#field-category').val());
              }
          }
      );
    
  • Second attempt:

      $('#category').val($('#field-category').val());
    

P.S.: #field-category has a value its a hidden input field and works OK.

  • 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-19T00:12:05+00:00Added an answer on June 19, 2026 at 12:12 am

    You need to use the initSelection option to set the initial value.

    If you are using a pre-defined select element to create the select2, you can use the following method

    $('select').select2().select2('val','3')
    

    Demo: Fiddle

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

Sidebar

Related Questions

I written the following code to randomly select items n items from a list
i don't understand why the following code, sometimes shows all the items i select,
I'm having problems with getting selected items in a select-list. Product product = _pr.GetProducts().ByProductID(productID).First();
MyTable ======= Item NVARCHAR(200) Hidden BIT I need to load all the items from
I'm having trouble accessing the value of a calculated field from a list which
I have a query with loads of columns. I want to select rows where
In Sql Server when you select to modify a SP or UDF it loads
I load a form and dynamically populate a select via AJAX from a PHP
I have a select dropdownlist with 1 item selected at page load in html.
I am trying to load mysql data from my database from a html select

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.