Javascript to hide selected option
<p>I have this code to hide selected options:</p>

<pre><code>function connect()
{
    $(".selectbox option").show();
    $(".selectbox").each(function(i) { 
        var obj = $(".selectbox option[value='" + $(this).val() + "']");
        if($(this).val() != "") obj.hide();     
    }); 
}

function to()
{
    $(".selectboxes option").show();
    $(".selectboxes").each(function(i) { 
        var obj = $(".selectboxes option[value='" + $(this).val() + "']");
        if($(this).val() != "") obj.hide();     
    }); 
}
</code></pre>

<p>but my problem now is that, I use PHP to generate the select tag, and in that php code i have a condition that once it sees this value it will automatically add selected=selected. but my JS would still display that variable in the drop down even though it is already selected. i tried adding:</p>

<pre><code>$('.selectboxes option:selected').find("option").hide();
</code></pre>

<p>but it did not work. any idea on how should i solve this problem?</p>

<p>BTW: i forgot to mention that, the php code will generate multiple select tags with the same values that will use that function, thus when i have 3 select tags 1 will have the pre selected value and the other 2 will be null, now when i click on either 2 of those that have no values selected yet i can still see in the drop down the choice that was already pre selected in select 1, what i wanted to do is that it should be automatically hidden, with that function it will not hide it until i select other choices from the drop down. since this line:</p>

<pre><code>$(".selectbox option").show();
</code></pre>

<p>would display all choices in the drop down, is there a condition for it to exempt "this" value?</p>

<p>SELECT PART:</p>

<pre><code>for($z=0;$z&lt;$rows_updatedrow;$z++)
{
?&gt;
&lt;select id = "sc" name = "connect_array[]" class="input-select selectbox" onchange = "connect()"&gt;
&lt;option value = ""&gt;--Select--&lt;/option&gt;
&lt;?php
for($zz=0;$zz&lt;$rows_getconnect;$zz++)
{
    $data_getconnect = mysql_fetch_assoc($query_getconnect);
    $field_name_getconnect[] = $data_getconnect['field_name'];
    $field_display_getconnect[] = $data_getconnect['field_display'];
    $field_type_getconnect[] = $data_getconnect['field_type'];
    if((($field_name_getconnect[$zz] == "friends_name" &amp;&amp; $connect == 2) || $field_type_getconnect[$zz] == "email") &amp;&amp; $z == 0){
    $selected = "selected=selected";
    }else{
    $selected = "";
    }
?&gt;
&lt;option value = "&lt;?php echo $field_name_getconnect[$zz]; ?&gt;" &lt;?php echo $selected; ?&gt;&gt;&lt;?php echo $field_display_getconnect[$zz]; ?&gt;&lt;/option&gt;
&lt;?php
}
?&gt;
&lt;/select&gt;
 connect to 
&lt;br/&gt;
&lt;?php
}
?&gt;
&lt;/div&gt;
&lt;div class = "right"&gt;
&lt;?php
for($a=0;$a&lt;$rows_updatedrow;$a++)
{
?&gt; 
&lt;select name = "to_array[]" class="input-select selectboxes" onchange = "to()"&gt;
&lt;option class = "option" value = ""&gt;--Select--&lt;/option&gt;
&lt;?php
for($aa=0;$aa&lt;$rows_getto;$aa++)
{
    $data_getto = mysql_fetch_assoc($query_getto);
    $field_name_getto[] = $data_getto['field_name'];
    $field_display_getto[] = $data_getto['field_display'];
    $field_type_getto[] = $data_getto['field_type'];
    if((($field_name_getto[$aa] == "friends_name" &amp;&amp; $to == 2) || $field_type_getto[$aa] == "email") &amp;&amp; $a == 0){
    $selected = "selected=selected";
    }else{
    $selected = "";
    }
?&gt;
&lt;option class = "option" value = "&lt;?php echo $field_name_getto[$aa]; ?&gt;" &lt;?php echo $selected; ?&gt;&gt;&lt;?php echo $field_display_getto[$aa]; ?&gt;&lt;/option&gt;
&lt;?php
}
</code></pre>

<p>thank you</p>
