tags:

views:

24

answers:

2

I have the following code. What I'm trying to do is to show a div named "uploader" when "Yes" is selected in the dropdown. It's currently not working.

$(document).ready(function() {
  $("#uploader").hide();
  $("#CitedIn").change(function() {
    if (("#CitedIn").val()  == 'yes')
       $("#uploader").show("fast");
    else $("#uploader").hide("fast");
    });
});

<table>
    <tr><td>Need item(s)?</td><td>
        <select id="CitedIn" name="CitedIn" size="1"  tabindex="13">
            <option value="none">(Select One)</option>
            <option value="Yes">Yes</option>
            <option value="No">No</option>
        </select>
    </td></tr>
</table>

<div id="uploader">
    Something...
</div>

What can done to make it work as intended?

+1  A: 

String comparison in javascript is case sensitive, you are comparing Yes to yes.

Besides, you are missing the $ call on this line

if (("#CitedIn").val()  == 'Yes')

As it should be:

if ($("#CitedIn").val()  == 'Yes')
    ^

Check here: http://jsfiddle.net/Lpg2k/

aularon
Didn't realized case mattered. I also needed $ Thanks!!!
codeLearner
A: 

You don't have the $ before the declaration in the if statement

  $("#CitedIn").change(function() { 
    if ($("#CitedIn").val()  == 'Yes')
       $("#uploader").show("fast"); 
    else $("#uploader").hide("fast");
    });

As others have noted, you also need to compare the same case, Yes != yes.

http://jsfiddle.net/Em2WD/

Robert