/ Published in: jQuery
Show a form field if 1 value from a dropdown is chosen, hide is the other is chosen. Can be extended to include more fields and values. Could get messy if you start nesting more than 2 'if else' but it gets the job done.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(document).ready(function() { $('#form-btw').hide(); //hide field on start $('#Klant').change(function() { var $index = $('#Klant').index(this); if($('#Klant').val() != 'professional') { //if this value is NOT selected $('#form-btw').hide(); //this field is hidden } else { $('#form-btw').show();//else it is shown } }); }); --- <select name="Klant" id="Klant"> <option id="field-particulier" value="particulier">Particulier</option> <option id="field-professional" value="professional">Professional</option> </select> <input name="BTW" type="text" class="form-text" id="BTW" />
URL: http://www.josephijs.be/bestellen.html