I created a form for my company's client. I used a basic validation to check to see if the user filled out all fields but there is a conditional question. If the user checks no, they have to fill out the field below. I want to create a validation that basically alerts the user to fill in the field if the box is checked no. I kind of have an idea how to do it but am missing something. Can somebody point me in right direction?
Below is the original script that checks to see if all fields and checkboxes are filled in:
function validateComplete(formObj)
{
if (emptyField(formObj.targetDate))
alert("Please enter the Target Date."
;
else if (emptyField(formObj.ssrNum))
alert("Please enter the SSR Number."
;
else if (emptyField(formObj.departmentName))
alert("Please enter the Department."
;
else if (emptyField(formObj.contactPerson))
alert("Please enter the Contact Person."
;
else if (emptyField(formObj.contactInitials))
alert("Please enter the Contact Person's three initials."
;
else if (emptyField(formObj.phoneNum))
alert("Please enter the Contact Person's phone number."
;
else if ( (document.initiationForm.claimType[0].checked != true) &&
(document.initiationForm.claimType[1].checked != true) &&
(document.initiationForm.claimType[2].checked != true) &&
(document.initiationForm.claimType[3].checked != true) &&
(document.initiationForm.claimType[4].checked != true) )
alert("Please choose a type of claim."
;
else if (emptyField(formObj.releaseDate))
alert("Please enter the Release Date."
;
else if ( (document.initiationForm.time[0].checked != true) &&
(document.initiationForm.time[1].checked != true) )
alert("Please choose quarterly or bi-weekly."
;
else if (emptyField(formObj.testRegion))
alert("Please enter the Test Region."
;
else if (emptyField(formObj.expectedCases))
alert("Please enter the Number of Expected Cases."
;
else if ( (document.initiationForm.gdg[0].checked != true) &&
(document.initiationForm.gdg[1].checked != true) )
alert("Please choose yes or no."
;
else return true;
return false;
}
//Check to see if field is empty
function emptyField(textObj)
{
if (textObj.value.length == 0) return true;
for (var i=0; i<textObj.value.length; ++i) {
var ch = textObj.value.charAt(i);
if (ch != ' ' && ch != '\t') return false;
}
return true;
}
Below is the original script that checks to see if all fields and checkboxes are filled in:
function validateComplete(formObj)
{
if (emptyField(formObj.targetDate))
alert("Please enter the Target Date."
else if (emptyField(formObj.ssrNum))
alert("Please enter the SSR Number."
else if (emptyField(formObj.departmentName))
alert("Please enter the Department."
else if (emptyField(formObj.contactPerson))
alert("Please enter the Contact Person."
else if (emptyField(formObj.contactInitials))
alert("Please enter the Contact Person's three initials."
else if (emptyField(formObj.phoneNum))
alert("Please enter the Contact Person's phone number."
else if ( (document.initiationForm.claimType[0].checked != true) &&
(document.initiationForm.claimType[1].checked != true) &&
(document.initiationForm.claimType[2].checked != true) &&
(document.initiationForm.claimType[3].checked != true) &&
(document.initiationForm.claimType[4].checked != true) )
alert("Please choose a type of claim."
else if (emptyField(formObj.releaseDate))
alert("Please enter the Release Date."
else if ( (document.initiationForm.time[0].checked != true) &&
(document.initiationForm.time[1].checked != true) )
alert("Please choose quarterly or bi-weekly."
else if (emptyField(formObj.testRegion))
alert("Please enter the Test Region."
else if (emptyField(formObj.expectedCases))
alert("Please enter the Number of Expected Cases."
else if ( (document.initiationForm.gdg[0].checked != true) &&
(document.initiationForm.gdg[1].checked != true) )
alert("Please choose yes or no."
else return true;
return false;
}
//Check to see if field is empty
function emptyField(textObj)
{
if (textObj.value.length == 0) return true;
for (var i=0; i<textObj.value.length; ++i) {
var ch = textObj.value.charAt(i);
if (ch != ' ' && ch != '\t') return false;
}
return true;
}