// JavaScript Document // Form Validation function validateForm() { // Usage - array 0 is the form name, then array 1+ the name of required fields // Get the name of fields that are required var argv = validateForm.arguments; var argc = argv.length; var form_name = argv[0]; var errors=""; for (var i = 1; i < argc; i++) { if (document.forms[form_name].elements[argv[i]].value == "") { // Check to see whether the name field is blank if(argv[i]=="name") { argv[i]="Please tell us your name."; } if(argv[i]=="address1") { argv[i]="Please tell us your the first line of your address."; } if(argv[i]=="city") { argv[i]="Please tell us your city/town location."; } if(argv[i]=="postcode") { argv[i]="Please tell us your postcode."; } if(argv[i]=="telephone") { argv[i]="Please tell us your telephone number."; } if(argv[i]=="username") { argv[i]="Please enter a username."; } if(argv[i]=="password") { argv[i]="Please enter a password."; } if(argv[i]=="email") { argv[i]="Please tell us your email address."; } if(argv[i]=="mobile") { argv[i]="You must specify a mobile number."; } if(argv[i]=="subject") { argv[i]="You must type in a subject"; } if(argv[i]=="message") { argv[i]="You must type in a message."; } if(argv[i]=="usersNAME") { argv[i]="You must type in your name."; } if(argv[i]=="usersEMAIL") { argv[i]="You must type in your email address."; } errors=errors+"\n\n- "+argv[i]+" "; } } if(errors) { alert("\nSorry you have not completed all of the required fields."+errors+"\n\n"); return(false); } else { // Disable the submit button to stop people clicking twice document.forms[form_name].elements['Submit'].disabled = true; document.forms[form_name].submit(); } }