Check if option is selected with jQuery,if not,then select a default value.

vishalneeraj-24503
Posted by vishalneeraj-24503 under jQuery category on | Points: 40 | Views : 448
Suppose,we have a dropdown list as below:-
<select id="ddl_number" multiple="multiple">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
<option value="4">Fourth</option>
</select>

<script type="text/javascript">
$(document).ready(function()
{
if (!$("#ddl_number option:selected").length)
$("#ddl_number option[value='3']").attr('selected','selected');
});
</script>

Comments or Responses

Login to post response