talena6
talena6

Reputation: 317

Trying to show a field when an option is selected in my form with jQuery but it is not working. What am I doing wrong?

I want my class of .fein to show when "llc" is selected from the dropdown but it is not working.

http://jsfiddle.net/0c7952hs/1/

<select>
    <option value="corporation">Corporation</option>
    <option value="llc">LLC</option>
    <option value="partnership">Partnership</option>
</select>

<div class="fein">
    <label for="fein">FEIN</label>
    <input type="password" name="fein" />
</div>

and the jquery:

$("option").change(function () {
    if ($(this).val() == "llc") {
      $('.fein').show();
    } else {
        $('.fein').hide();
      }
});

Upvotes: 0

Views: 22

Answers (2)

John
John

Reputation: 312

When I've done something similar, I hide the element using JavaScript onload instead of hiding it with CSS initially. I suggest starting there. In addition, you're not changing the options, you're changing the select, you should be referencing that.

Upvotes: 0

Jeremy Thille
Jeremy Thille

Reputation: 26380

Replace $("option") with $("select").

Upvotes: 3

Related Questions