jquery select option based on value

By using jquery you can easily select an option selectd by based on that option value.

Example of Jquery select option selected based on value:

<select id="mySelect" 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 (!$("#mySelect option:selected").length)
    $("#mySelect option[value='3']").attr('selected', 'selected');
});
</script>

In Dynamic Jquery you can use this code by following:

 var vatId = parseInt(data);
 $("#vatCategoryId option[value='"+vatId+"']").attr('selected', 'selected');

You may also like...

Leave a Reply