2

Basically I'm trying to hide dropdownlist1 when dropdownlist2's selected value is "example".

Is this possible with jquery?

1 Answer 1

5

Yes its possible, just bind a function to the change event and look at the value.

Live Demo

$('#dp1').change(function(){
    if(this.value === 'example'){
        $('#dp2').hide();  
    }else{ // If you want it to show on other values
        $('#dp2').show(); 
    }
});

Reference

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

5 Comments

Your exmample doesn't work properyly, you are are setting the drop down equal to example instead of checking the value. Try this one jsfiddle.net/guanome/4mAmQ/5
heh yeah I caught that a second before and changed it :P, thanks though.
@Thai I considered that but the OP didn't ask it to do that, Ill add it though.
Thanks @pixelbobby I like the lowercase check, but I prefer to use the pure JS way of getting the value rather that using .val(), micro optimization I know :)
Np. You're right and I agree with you; I was troubleshooting the code and forgot to put it back to this.val. good call.

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.