user3364140
user3364140

Reputation: 23

dropdown jquery range value

I'm a novice in regards to javascript/ jquery, I needed help as I wanted anyone who picks cohort 1-12 in my fiddle below to be able to view the hidden business name text box.

HTML:

<body>
<select id='purpose'>
<option value="0">Personal use</option>
<option value="1">Business use</option>
<option value="2">Passing on to a client</option>
</select>
<div style='display:none;' id='business'>Business Name<br/>&nbsp;
<br/>&nbsp;
    <input type='text' class='text' name='business' value size='20' />
    <br/>
</div>
</body>

JS:

$(document).ready(function(){
    $('#purpose').on('change', function() {
      if ( this.value == '1')
      {
        $("#business").show();
      }
      else
      {
        $("#business").hide();
      }
    });
});

FiDDLE: http://jsfiddle.net/pranavcbalan/v4gNL/

Any help on this would be much very appreciated.

Thanks

Upvotes: 2

Views: 530

Answers (1)

JTG
JTG

Reputation: 8836

If I'm understanding you correctly, you want to show the business element as long as someone doesn't pick <option value="0">Personal use</option>. Then your logic is reversed, you want to hide the business element when someone picks option 0.

$(document).ready(function(){
    $('#purpose').on('change', function() {
      if ( this.value == '0')
      {
        $("#business").hide();
      }
      else
      {
        $("#business").show();
      }
    });
});

Fiddle Demo

Upvotes: 1

Related Questions