Showing posts with label form validation with prototype. Show all posts
Showing posts with label form validation with prototype. Show all posts

Tuesday, December 20, 2011

Simple Form Validation with Prototype

1:  <script src="prototype.js"></script>  
2:  <script>  
3:    //example: checkForm('myForm');  
4:    function checkForm(frm)  
5:    {  
6:      allFields = Form.getElements("myForm");  
7:      for(i=0;i<allFields.length;i++)  
8:      {  
9:        if(allFields[i].value == "")  
10:        {  
11:          $(allFields[i]).addClassName('error');  
12:        } else {  
13:          $(allFields[i]).removeClassName('error')  
14:        }  
15:      }  
16:    }  
17:  </script>