jquery - How to change the selected option of a select by using JavaScript? -
jquery - How to change the selected option of a select by using JavaScript? -
i've got simple problem can't figure out how ... in html page, have simple select tag :
<select id="selection-type"> <option disabled="disabled">type</option> <option value="0">tous les types</option> <option value="1">appartement</option> <option value="2">maison</option> <option value="3">terrain</option> </select>
i want set specific value dynamically using javascript, managed alter selected index, , not displayed value. currently, i'm doing (in footer section of html page) :
<script type="text/javascript"> $(document).ready(function(){ document.getelementbyid("selection-type").selectedindex = 2; }); </script>
and in result, it's alter selected index of select, displayed text not "update" : value "tous les types" stays. in fact, want alter whole selection, e.g. selected alternative , not index.
it looks you're using jquery. utilize jquery's val
method alter select box, using value
of alternative want select:
$(document).ready(function() { $('#selection-type').val('1'); });
or need done in plain javascript?
edit:
what browser using? selectedindex
thing you're doing work me in chrome 24.0.1312.5.
jquery html select
Comments
Post a Comment