Posted By

fuzzylogic on 04/09/08


Tagged


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

SmpleJohn
osdesk
blackabee
korzhik
loric
seanpowell


Simple form validation


 / Published in: JavaScript
 

  1. function Validate(CheckFields) {
  2.  
  3. var ShowAlert = false;
  4. var ArrFields = CheckFields.split(",");
  5. for (var x = 0; x < ArrFields.length; x++) {
  6. var TargetField = document.getElementById(ArrFields[x]);
  7.  
  8. if (TargetField.value == '') {
  9. TargetField.style.backgroundColor = '#EF9999';
  10. TargetField.onclick = function(){
  11. this.style.backgroundColor = '#FFF';
  12. }
  13. ShowAlert = true;
  14. }
  15. }
  16.  
  17. if (ShowAlert == true) {
  18. alert("You have not filled in all the required fields. \n Please fill in all the fields marked in red.");
  19. scroll(0,0);
  20. } else {
  21. document.form1.submit();
  22. }
  23.  
  24. }

Report this snippet  

You need to login to post a comment.