Set selected option of select box

Upvote

I want to set a option that was selected previously to be displayed on page load. I tried it with the following code:

$("#gate").val('Gateway 2');

with

<select id="gate">
    <option value='null'>- choose -</option>
    <option value='gateway_1'>Gateway 1</option>
    <option value='gateway_2'>Gateway 2</option>
</select>

But this does not work. Any ideas?

Darin Dimitrov

This definitely should work. Here's a demo. Make sure you have placed your code into a $(document).ready:

$(function() {
    $("#gate").val('gateway_2');
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Set select option 'selected', by value

From Dev

How to set the selected option of <select>

From Dev

How to set the selected option of <select>

From Dev

Remove selected option from another select box

From Dev

jQuery adding option to select box with selected arbitrate

From Dev

How to set an option from multiple options or array with different values to views as selected in select box using PHP

From Dev

Change select box value depending other selected option box

From Dev

Get select box option before the currently selected option

From Dev

How to set the selected value in aui:select box

From Dev

Spring mvc - select set selected option

From Dev

Struts <html:select> set selected option dynamically

From Dev

How to disable all option second select box that can be less than to first select box selected option?

From Dev

Select option selected an not selected

From Dev

Disable/Enable a text box based on radio/select option selected Javascript

From Dev

How to disable a select box without unchecking the selected option?

From Dev

Meteor Select Box - mark option as selected depending on data context

From Dev

How the rails select box selected option is giving from coffee file

From Dev

JQuery set dropdown list box selected option - not by value, but by display text

From Dev

How to set selected value for select box from inside directives link

From Dev

AngularJS select seems to need to match on the same object to set the selected option

From Dev

How to set the 'selected option' of a select dropdown list with jquery

From Dev

How to set selected option of select element by its ID?

From Dev

set selected value of select field if option with that value does not exist

From Dev

How do I to set selected value in a select option using jquery?

From Dev

set selected value of a select input to another selects option value

From Dev

Rails select options - set first option as disabled, selected

From Dev

How do I to set selected value in a select option using jquery?

From Dev

How do I set a selected option for select in Angular

From Dev

How to set selected option of select element by its ID?

Related Related

  1. 1

    Set select option 'selected', by value

  2. 2

    How to set the selected option of <select>

  3. 3

    How to set the selected option of <select>

  4. 4

    Remove selected option from another select box

  5. 5

    jQuery adding option to select box with selected arbitrate

  6. 6

    How to set an option from multiple options or array with different values to views as selected in select box using PHP

  7. 7

    Change select box value depending other selected option box

  8. 8

    Get select box option before the currently selected option

  9. 9

    How to set the selected value in aui:select box

  10. 10

    Spring mvc - select set selected option

  11. 11

    Struts <html:select> set selected option dynamically

  12. 12

    How to disable all option second select box that can be less than to first select box selected option?

  13. 13

    Select option selected an not selected

  14. 14

    Disable/Enable a text box based on radio/select option selected Javascript

  15. 15

    How to disable a select box without unchecking the selected option?

  16. 16

    Meteor Select Box - mark option as selected depending on data context

  17. 17

    How the rails select box selected option is giving from coffee file

  18. 18

    JQuery set dropdown list box selected option - not by value, but by display text

  19. 19

    How to set selected value for select box from inside directives link

  20. 20

    AngularJS select seems to need to match on the same object to set the selected option

  21. 21

    How to set the 'selected option' of a select dropdown list with jquery

  22. 22

    How to set selected option of select element by its ID?

  23. 23

    set selected value of select field if option with that value does not exist

  24. 24

    How do I to set selected value in a select option using jquery?

  25. 25

    set selected value of a select input to another selects option value

  26. 26

    Rails select options - set first option as disabled, selected

  27. 27

    How do I to set selected value in a select option using jquery?

  28. 28

    How do I set a selected option for select in Angular

  29. 29

    How to set selected option of select element by its ID?

HotTag

Archive