monecchi

Show form input fields based on select value

Mar 2nd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.78 KB | None | 0 0
  1. <select name="dbType" id="dbType">
  2.    <option>Choose Database Type</option>
  3.    <option value="oracle">Oracle</option>
  4.    <option value="mssql">MS SQL</option>
  5.    <option value="mysql">MySQL</option>
  6.    <option value="other">Other</option>
  7. </select>
  8.  
  9. <div id="otherType" style="display:none;">
  10. <label for="specify">Specify</label>
  11. <input type="text" name="specify" placeholder="Specify Databse Type"/>
  12. </div>
  13.  
  14. //Original discussion and solution here: http://stackoverflow.com/questions/15566999/how-to-show-form-input-fields-based-on-select-value | http://jsfiddle.net/ks6cv/
  15.  
  16. $('#dbType').on('change',function(){
  17.      var selection = $(this).val();
  18.     switch(selection){
  19.     case "other":
  20.     $("#otherType").show()
  21.    break;
  22.     default:
  23.     $("#otherType").hide()
  24.     }
  25. });
Advertisement
Add Comment
Please, Sign In to add comment