1
Are two problems:
1 - When loading an input select I tried to use a Trigger to force "change", but it did not take effect.
2 - I have 2 selects. When I actually change the value of the first, the change event is called and "hides" values of the other select, but if the value that was hidden is the current selected it does not disappear from the combo, only from the list.
How to make the initial change work and how to make the items I tried to hide disappear correctly?
Follow the fiddle code for error checking: http://jsfiddle.net/T52EE/
JS:
$("#cb").trigger("change");
$("#cb").on("change", function(){
var cb1val = $(this).val();
$("#cb2 option").each(function(){
if($(this).val() <= cb1val){
$(this).hide();
}
else{
$(this).show();
}
});
});
HTML:
<select id="cb">
<option value="0">Valor 1</option>
<option value="1">Valor 2</option>
<option value="2">Valor 3</option>
<option value="3">Valor 4</option>
<option value="4">Valor 5</option>
</select>
<select id="cb2">
<option value="0">Valor 1</option>
<option value="1">Valor 2</option>
<option value="2">Valor 3</option>
<option value="3">Valor 4</option>
<option value="4">Valor 5</option>
</select>
The second problem is a little confusing.
– Silvio Andorinha
I updated the fiddle. When I select "Value 1" in the first select "Value 1" must be hidden from the second select. But he keeps appearing, just disappears from the list. At least on Chrome.
– Joao Paulo
Ready edited the reply
– Silvio Andorinha
The first problem was that the forced no change should be after the change function. And he checked this. And the second problem I explained in the comment of your answer and based on his to do the way I expected. Anyway thank you very much.
– Joao Paulo