Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Conditional Verification"

Status
Not open for further replies.

zoser

Programmer
May 9, 2002
39
US
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;

}

 
Simplify. This as a Form Design issue, not Input Validation. If the user has to fill in a field as a consequence of checking a box then you solve your validation problem simply by removing the user's direct access to the check box.

Set up the form so the user has to fill in the field to get a No check, otherwise the default display is Yes. The check box is display only, gives the user handy feedback. Easier for both you and your users.
 
that sounds good but how do i make that work?

(i am still learning)
 
zoser-

I think what wray is trying to say is that you should just test to see if the user filled out the information in the field, then you know that they would have checked the box. for example, say you have some form that is collecting product information.

In that form you have a checkbox that says &quot;you bought a cd player&quot; and then a textarea that says above it, &quot;if yes then why:&quot;

but couldn't you just do this instead? put in a textarea with description &quot;If you bought a cd player, then why? :&quot;

with the second example, your form is less cluttered and easier to understand.


and btw, I should hope that everyone in this forum is still learning! :)I Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top