/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function Validate(CheckFields) { var ShowAlert = false; var ArrFields = CheckFields.split(","); for (var x = 0; x < ArrFields.length; x++) { var TargetField = document.getElementById(ArrFields[x]); if (TargetField.value == '') { TargetField.style.backgroundColor = '#EF9999'; TargetField.onclick = function(){ this.style.backgroundColor = '#FFF'; } ShowAlert = true; } } if (ShowAlert == true) { alert("You have not filled in all the required fields. \n Please fill in all the fields marked in red."); scroll(0,0); } else { document.form1.submit(); } }