1

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

0

2 Answers 2

2

try change

$("#select1").val($(this).val());

to

$("#select1 :selected").val($(this).val());

( I assume you want to change the value of the currently selected element in select1 based on what you selected in select2 )

0

it works for me. Note that you are binding to the select2 change event not the select1 change event. So when you change select 2, select 1 should change if it has a higher value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.