-1

Hi this is giri
i need ur help that is
i am trying to select two drop down option in html and i want compare to options if those options are equal than it as two redirect to respective page ,will u please provide with a code .
thank you

4
Contributors
4
Replies
33
Views
1 Year
Discussion Span
Last Post by gentlemedia
0

ready done!

<select id="select_one" onchange="selection_changed();">
<option value="1">one</option>
<option value="2">two</option>
</select>

<select id="select_two" onchange="selection_changed();">
<option value="1">one</option>
<option value="2">two</option>
</select>

selection_changed(){
if( $("select_one").val()==$("select_two").val(){
    window.location="http://example.com";
}
}
0

@TextWiller, you forgot the '#' on the jQuery selectors.
But since you're using jQuery, I think this is better:

    <select class="whatched_select" >
    <option value="1">one</option>
    <option value="2">two</option>
    </select>
    <select class="whatched_select" >
    <option value="1">one</option>
    <option value="2">two</option>
    </select>
    <script type="text/javascript">
    $(function() {
        var $selects = $(".whatched_select");
        $selects.change(function() {
            if ( $selects.eq(0).val() == $selects.eq(1).val() ) {
                window.location = "http://redirectpage.com.br";
            }
        });
    });
    </script>
0

@ AleMonteiro
I can agree with you, I have choosen that way because I often work together with web designers
They are accustomed to change classes and ids . if they see there is an event in html they understand something is going on that item
Moreover when javascript is in an attched file

Edited by TexWiller: mispell

1

They are accustomed to change classes and ids . if they see there is an event in html they understand something is going on that item

It's best practice to separating out any JavaScript behavior code from your markup and presentation. It's called unobstrusive JavaScript. If you work with web designers then you could decouple your JavaScript classes from the CSS ones by using a prefix.

<button class="btn js-popup">click here</button>

Like this, web designers know that the btn class is for styling and (other) JavaScript developers know the js-popup class is for behavior.

Edited by gentlemedia

Votes + Comments
Nice idea!
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.