Drop down validation


/ Published in: JavaScript
Save to your folder(s)

requires that a pulldown \\\"program1\\\" in form \\\"freshmen\\\" be set to anything but the first value in the option list. \\r\\n\\r\\nrequires jquery validate: http://docs.jquery.com/Plugins/Validation


Copy this code and paste it in your HTML
  1. jQuery.validator.addMethod(
  2. "selectNone",
  3. function(value, element) {
  4. //alert(element.options.selectedIndex);
  5. //if (element.value == "blank"){
  6. if (element.options.selectedIndex == "0"){
  7. return false;
  8. }
  9. else return true;
  10. },
  11. "Please select an option."
  12. );
  13.  
  14. $(document).ready(function(){
  15.  
  16.  
  17. $("#freshmen").validate({
  18. rules: {
  19. program1: {
  20. selectNone: true
  21. }
  22. }
  23.  
  24. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.