jquery Drop down select value – Education Career Blog

   html += "<table><tr><td> <label for='id_first_name' ><b>Timezone:</b></label> </td>";
   html += '<td><select id="timezone" name="nodes" style="width:300px;margin:5px;">';
   {% for tz in all_timezones %}
   if('{{tz}}' == 'Asia/Calcutta')
        html+='<option value="{{tz}}" selected>{{tz}}</option>';
        html += '<option value="{{tz}}">{{tz}}</option>';
   {% endfor %}
   html += '</select>';
   html += "</td> </tr>";

Now when i want to edit ,i know the previous value stored .And lets say that as Asia/Bangkok how to get this value selected
an example

    var edit_val="Asia/Bangkok"

    $("#timezone selected valedit_val")//Sumthing like this

     In the drop downlist i want this value to be selected


Try putting this below you dropdown:

<script type="text/javascript">
   document.getElementById('timezone').value = 'Asia/Bangkok';

Let’s know if that helps.

Leave a Comment