tags:

views:

29

answers:

3

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?

Thanks

Jamie

+2  A: 

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();
        }​​​
    });
});
Darin Dimitrov
Doesn't seem to work http://jsfiddle.net/ExtWV/1/
Jamie Taylor
That fiddle works for me? You sure you have javascript enabled?
Alex
Yea definitely got javascript enabled - I'm using Safari on Mac - but have tried it in Chrome too and it doesn't work
Jamie Taylor
@Jamie can you try this in a separate file, not jsfiddle? It seems like a bug there.
Darin Dimitrov
+2  A: 

I think you are missing ;
Check here

vinothkumar
That doesn't work either?
Jamie Taylor
Did you get any errors?I tested in firefox.Its working fine for me.
vinothkumar
Are you looking for when 1 and 2 is selected it needs to be hide?
vinothkumar
+2  A: 

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)

Marwelln
Thanks that works for me
Jamie Taylor