Posted By

dan_hoerr on 08/12/10


Tagged

dropdown jquery validation


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

supermauerbros


Drop down validation


 / Published in: JavaScript
 

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

  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  

You need to login to post a comment.