pass php variable to select the right option
<p>I'm trying to select the option based on the php variable value. So I need <code>option value=1</code> is selected in the first <code>&lt;select&gt;</code> and <code>option value=6</code> selected in second . Since I have a bunch of other <code>&lt;select&gt;</code> in the form, eventually, I will have an php array of some values, and I need each of the value match up with the option value under corresponding index in the a group of <code>&lt;select&gt;</code> that sharing the same <code>class='si_1'</code>, and assign <code>selected</code> to that option. </p>

<p>Thanks</p>

<p>php part</p>

<pre><code>&lt;?php 
$select_1 = "1";
$select_2 = "6";
?&gt;
</code></pre>

<p>JQuery part</p>

<pre><code>$(document).ready(function(){
    var sel_class = $(".si_1");
    var array = {"&lt;?php echo $select_1?&gt;","&lt;?php echo $select_2?&gt;"};
    JQuery.each(array, function(index, value) {
        var current = sel_class.get(index);
        $(current + " option[value=" + value + "]").attr('selected', 'selected');
    });
});
</code></pre>

<p>I don't know if <code>$(current + " option[value=" + value + "]")</code> is the correct syntax to target the <code>&lt;select&gt;</code> at <code>index in $(".si_1")</code> that has <code>option</code> where the <code>option attribute value</code> has value that's at <code>index in array</code></p>

<p>HTML part</p>

<pre><code>&lt;select class="si_1"&gt;
    &lt;option value="1"&gt;Test 1&lt;/option&gt;
    &lt;option value="3"&gt;Test 3&lt;/option&gt;
    &lt;option value="5"&gt;Test 5&lt;/option&gt;
    &lt;option value="7"&gt;Test 7&lt;/option&gt;
&lt;/select&gt;
&lt;select class="si_1"&gt;
    &lt;option value="2"&gt;Test 2&lt;/option&gt;
    &lt;option value="4"&gt;Test 4&lt;/option&gt;
    &lt;option value="6"&gt;Test 6&lt;/option&gt;
    &lt;option value="8"&gt;Test 8&lt;/option&gt;
&lt;/select&gt;
</code></pre>
