|
Hi, I have these 2 validate function, how can put them together?
My main purpose is add validation for 3 radio button group to the existing validation form I found from webwiz site.
I tried added the red part, but still doesn't work.
this part is taken from web wiz CONDTS form
------------------------------
function Checkform() {
var errorMsg = "";
if (document.Form.firstName.value == ""){ errorMsg += "\n\tFirst Name \t- Enter your First Name"; } if (document.Form.lastName.value == ""){ errorMsg += "\n\tLast Name \t- Enter your Last Name"; } if (document.Form.contact.value == ""){ errorMsg += "\n\tContact \t- Enter your contact number"; } if (document.Form. radioButton1.checked == true){ errorMsg += "\n\tType \t- Enter the type"; } if ((document.Form.email.value == " mailto:%22%20%20document.formContact.email.value.length%20%3e%200%20&&%20document.formContact.email.value.indexOf%22@%22,0 - ") || (document.formContact.email.value.length > 0 && (document.formContact.email.value.indexOf("@",0 ) == - 1 || document.formContact.email.value.indexOf(".",0) == - 1))) { errorMsg += "\n\tE-mail Address \t- Enter your valid e-mail address"; } if (errorMsg != ""){ msg = "______________________________________________________________\n\n"; msg += "Enquiry has not been sent because there are problems with the form.\n"; msg += "______________________________________________________________\n\n"; msg += "The following fields need to be corrected: -\n"; errorMsg += alert(msg + errorMsg + "\n\n"); return false; } return true; }
------------------------------
I found this other fuction that actually validate the radio group one by one. If the above statement doesn't work, is there any way I can incroporate the following code to it?
-------------------------------
function validateForm (form) { for (var e = 0; e < form.elements.length; e++) { var el = form.elements[e]; if (el.type == 'radio') { var group = form[el.name]; var checked = false; if (!group.length) checked = el.checked; else for (var r = 0; r < group.length; r++) if ((checked = group[r].checked)) break; if (!checked) { alert('Please check ' + el.name + ' radio button'); el.focus(); return false; } } } return true; }
------------------------------------------
|