I have several tables on a page with the possibility of multiple dropdowns in each table. The table and the dropdowns are autogenerated. The tables I want to target have numeric ids and all of the values of the dropdowns will be numeric.
HTML Sample Code for one of the tables I would like to target
<table id="15">
<tr>
<td>
<div id="dd_4_0">
<select id="4_0">
<option value=""></option>
<option value="18">VNDR64324</option>
<option value="21">MFG5321</option>
<option value="27">OTHER</option>
</select>
</div>
</td>
</tr>
<tr>
<td>
<div id="dd_2_6">
<select id="2_6">
<option value=""></option>
<option value="12">VN32R2345</option>
<option value="21">5678</option>
<option value="27">NEM</option>
</select>
</div>
</td>
</tr>
</table>
Once one of the dropdowns in the table are selected I would like to hide the other dropdowns. I have code that works but has a lot of iterating through loops that I would like to do without if possible. Is there a cleaner way to write this?
$('table').click(function() {
if($.isNumeric(this.id))
dd = $("#" + this.id + " select");
$.each(dd, function(){
if($.isNumeric($(this).val()))
{
selectedId = this.id;
$.each(dd, function(){
if(this.id != selectedId)
$('#dd_' + this.id).hide();
});
}
});
});