8

I can't seem to get this working seems like it should

$('.titleother').change(function() {

if ($('.titleother').val() == 'Other') {
    ​$('.hiddentext').css('display','block')
}​​​

})

For this HTML

<select class="titleother">​
<option value="1">1</option>
<option value="2">2</option>
<option value="Other">Other</option>
</select>

<p class="hiddentext" style="display:none">TEXT</p>

Any ideas?

3
  • Sure it doesn't work? Commented Oct 25, 2010 at 8:45
  • 1
    It doesn't seem to work for me? Commented Oct 25, 2010 at 8:46
  • 1
    in place of if ($('.titleother').val() == 'Other') ​$('.hiddentext').css('display','block') the better way is: ​$('.hiddentext').toggle($(this).val() == 'Other'); Commented Oct 25, 2010 at 9:34

3 Answers 3

17

This works for me using Chrome:

$(function(ready){
    $('.titleother').change(function() {
        if ($(this).val() == 'Other') {
            $('.hiddentext').show();   
        }
    });
});

http://jsfiddle.net/amuec/11/

(Darin's code didn't work for me either)

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

Comments

5

Make sure you put this in a $(document).ready so that the DOM is ready when you attach the .change() handler:

$(function() {
    $('.titleother').change(function() {
        if ($(this).val() == 'Other') {
            ​$('.hiddentext').show();
        }​​​
    });
});

4 Comments

That fiddle works for me? You sure you have javascript enabled?
Yea definitely got javascript enabled - I'm using Safari on Mac - but have tried it in Chrome too and it doesn't work
@Jamie can you try this in a separate file, not jsfiddle? It seems like a bug there.
@DarinDimitrov, for some reason your code has a \u200b zero-width space which causes the code to not to run.
4

I think you are missing ;
Check here

2 Comments

Did you get any errors?I tested in firefox.Its working fine for me.
Are you looking for when 1 and 2 is selected it needs to be hide?

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.