Hiding empty form option fields - Working but inelegant!
Hi all,
First post here - I am trying to hide options in a form select field if they are empty. The code below works...but even I know it must be a horrid way of doing it! Anyone care to tidy it up for me? I would learn much from the experience, thanks very much:
-
$(document).ready(function() {
var size1 = $(".Size1").val();
if(size1==' ')
{
$('.Size1').remove();
}
var size2 = $(".Size2").val();
if(size2==' ')
{
$('.Size2').remove();
}
var size3 = $(".Size3").val();
if(size3==' ')
{
$('.Size3').remove();
}
var size4 = $(".Size4").val();
if(size4==' ')
{
$('.Size4').remove();
}
});
Working against html:
-
<select name="os0">
<option class="Size1" value="8">8</option>
<option class="Size2" value="9">9</option>
<option class="Size3" value=""></option>
<option class="Size4" value=""></option>
</select>
[/code]