I have this select options color:
HTML:
<select id="selected_color" name="inkColor">
<option disabled selected>select color:</option>
<option id="red">Red</option>
<option id="blue">Blue</option>
<option id="green">Green</option>
<option id="black">Black</option>
</select>
I want to make a for loop javascript for this 4 lines that used for hide option that have value <= 0
JS:
$('option#red').attr("hidden", true);
$('option#blue').attr("hidden", true);
$('option#green').attr("hidden", true);
$('option#black').attr("hidden", true);
I try to make for loop for above code.
JS:
//TO HIDE SELECT COLOR THAT DOSE NOT HAVE A VALUE
//color values
red= -1;
blue=9;
green= -4;
black=3;
//red and green must be hide because it's less than 0
color_value = [red,blue,green,black];
for(var $x=0 ; $x < color_value.length ; $x++){ //first for loop
color_str=['red','blue','green','black'];
for(var $j=0 ; $j < color.length ; $j++){ //second for loop
ids = "option#"+color[$j];
if (color_value[$x] <= 0){
$(ids).attr("hidden", true);
}
}
}
You can see it on jsfiddle