0

i have this form ..

<form method="post" action=''>

    <select class="first">
       <option value="0">choose ...</option>
       <option value="1">Hello</option>
       <option value="3">It's</option>
    </select>

    <select class="second">
       <option value="0">choose ...</option>
       <option value="2">World</option>
       <option value="4">me</option>
    </select>

    <input type="text" class="dest" value="" />

</form>

and would like to dynamically gather selected informations with jQuery, because I need to decide on the selected values ...

When you select specific combination of OPTION values (lets say Hello + World) it should add some value to INPUT.dest and lock it (disable from editing) ...

But I can't make it work ... What I have, is that on each change of each select (separately only) i can map the actual value

  $(document).ready(function () {

    $(".first").change(function () {        
        var option = $(this).find("option:selected").val();
        $(".dest").val(option);
    });

    $(".second").change(function () {        
        var option2 = $(this).find("option:selected").val();
        $(".dest").val(option2);
    });

  });

Here is the live demo in fiddle

Do you know what am I missing? I know it will be just a little thing .. thank you

0

1 Answer 1

1

I would generalize it and use one event listener, and then gather the combination and do whatever:

$("select").change(function () {        
    var first = $(".first").find("option:selected").val();
    var second = $(".second").find("option:selected").val();

    if(first == 1 && second == 2)
            $(".dest").val("Hello world").prop("disabled",true);
    else
         $(".dest").val("Something else").prop("disabled",false);
});

http://jsfiddle.net/cxx428af/3/

Sign up to request clarification or add additional context in comments.

1 Comment

that's exactly what I was looking for !!!! thank you.. will mark it as answer as soon as it will be possible (told me I can't mark it in 3 min) .. .thank you !!!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.