jquery: change the value of `select1` onchange of `select2` IF $('#select2').val() < $('#select1').v
- by Syom
i've asked the first question about selects here, i thought, that when i resieve an answer, i would solve and the second part of my problem, but there was a short way to solve first problem, so i have to ask a question again, about second part:
i have two selects
<select id="select1">
<option value="1">1day</option>
<option value="2">2day</option>
<option value="3">3day</option>
</select>
<select id="select2">
<option value="1">1day</option>
<option value="2">2day</option>
<option value="3">3day</option>
</select>
and i need to change the value of select1 onchange of select2,
if $('#select2').val() < $('#select1').val();
i try to write the following function
$("#select2").bind('change',function() {
if($('#select2').val() < $('#select1').val())
{
$("#select1").val($(this).val());
}
});
but it doesn't eork, becouse on the moment of change, when i call the function, it doesn't change it's value yet.
so, what can i do?
Thakns