0

Is it possible to have a default option displayed in select box without changing the order of the other options?

<select>
    <option>
    1
    </option>
    <option>
    2
    </option>
    <option>
    3
    </option>
    <option>
    4
    </option>
    <option>
    5
    </option>
</select>
  1. Default 1 is displayed:

1 is first in option list so it is displayed first 2. I want 3 displayed as default without changing order of option list:

I want to display 3 a defualt

Enki
  • 1,565
  • 2
  • 13
  • 20
  • May be this helps you: [how-to-make-first-option-of-select-selected-with-jquery](http://stackoverflow.com/questions/1414276/how-to-make-first-option-of-select-selected-with-jquery). – Harry Joy Oct 03 '11 at 05:40

2 Answers2

0

try something like

$("select").val($("select option[value='fb']").val());

http://jsfiddle.net/qu5fF/

or if you are using jquery 1.6 or higher use prop

$("select option[value='fb']").prop("selected",true);

http://jsfiddle.net/qu5fF/1/

for jquery version lower then 1.6 you can use .attr

$("select option[value='fb']").attr("selected","selected");

http://jsfiddle.net/qu5fF/3/

Rafay
  • 30,950
  • 5
  • 68
  • 101
0

You can add the element at the 0 index.

<script type="text/javascript">
   var elem = document.getElementById('<%= DropDown.ClientID %>');
   var myNewOption = new Option(val.Name, val.ID);
   elem .options[elem .options.length] = myNewOption;
</script>
NomadTraveler
  • 1,086
  • 1
  • 12
  • 37