Tuesday, October 20, 2015

How do I dynamically set the selected option of a drop-down list using JQuery, Javascript and html?

In this below script, dynamically set the selected option of a drop-down list using JQuery, Javascript and html

dynamically set the selected option of a drop-down list using JQuery, Javascript and html
SCRIPT

<script type="text/javascript">
$(function(){
$("#gender").val("Male").attr('selected','selected");
});
</script>

HTML
<select id="gender" selected="selected">
                            <option>--Select--</option>
                            <option value="1">Male</option>
                            <option value="2">Female</option>
                        </select>

No comments:

Post a Comment