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>

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

In Dynamic Jquery you can use this code by following:

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

Rasel Ahmed

I'm a Computer Science graduate from Bangladesh. I complete my CSE in 2008. Now i am a Senior Software Engineer at Grameen Solutions Ltd. I work in Cakephp framework. I also have complete job in wordpress, joomla, titanium, Phpfox and magento.

You may also like...

1 Response

  1. Daniel says:

    Nice Post. so helpful

Leave a Reply