These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Check box reguirement problem

mroiniotis01
Registered: Dec 15 2010
Posts: 6

I have total of 11 check boxes that I want to be mandatory. With being maddatory I want to throw an error message when you click the submit by Email button just in case all the fields werent checked. Basically I don't want the end user submitting the form without properly checking all the boxes. I decided to run two Java scripts.
 
first java script for each check box which is a initialize event
this.mandatory = "error";
this.mandatoryMessage = " must view the terms and conditions.
 
second script
(I made sure to hide and exclude the orginal email sumbit button, and place a "fake" submit button.
 
used a click event on the fake submit button
 
if(checkbox1.rawValue ! = "1", checkbox2.rawValue ! = "1",etc......)
{
xfa.host.message (" must view the terms and conditions");
}
else
{
EmailSubmitButton1.execEvent("click");
 
I'm running into a problem with the second script. Problem is when not all 11 boxes are checked it shows the error message before opening Email (which I want). But if you only check couple the boxes and leave couple not checked it dosent show the error message (which I dont want to happen) just goes straight to email. I don't want the email popping up if boxes are unchecked, I want the error message showing if check boxes have yet to be checked. I feel im close with solving this problem.

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
What is the "Off" or not selected value for each of the check boxes?

Your if statement logical test statement does not have the correct syntax for a logical OR or AND test. I am assuming you want a logical OR test.

There is no 'xfa.host.message()' method.

Assuming the "Off" value for the check boxes is numeric 0:

// see if any check box is not checked
if(checkbox1.rawValue == 0 | checkbox2.rawValue == 0 |checkbox3.rawValue == 0 | (...) | checkbox11 == 0){
// an unchecked box has been found
xfa.host.messageBox(" must view the terms and conditions");
} else {
// all check boxes checked
EmailSubmitButton1.execEvent("click");
}


George Kaiser

mroiniotis01
Registered: Dec 15 2010
Posts: 6
the "off" value is 0.

is there another method I can use to show an error message?

thanks so much for your reply and information helped lot
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You can use either the 'xfa.host.messageBox()' or the "app.alert()' methods for JavaScript. In FormCalc 'xfa.host.messageBox()' is the only option available.

Spelling and capitalization are strictly enforced in most programing languages.

It is also easier to test code with a minimal amount of fields until you get the code working and then adding more fields for the more complex requirements. You might also want to look at the JavaScript debugging console when using preview to see if there are any errors. Also you may want to look at the 'Scripting Reference' under LiveCycle Designer's 'Help' menu option.

George Kaiser

mroiniotis01
Registered: Dec 15 2010
Posts: 6
well I added what you had now when i click sumbit the email never shows up. Your absoutely right about testing on minimal amount of fields. I ran test on one - three fields and it worked fine the way I wanted it too, seems like when I added more fields to the script I ran into this problem with the submitting and message error.
mroiniotis01
Registered: Dec 15 2010
Posts: 6
looks like once all the fields are selected and the user clicks submit again it dosen't go to the Email now. Nothing like java scripting headaches.
mroiniotis01
Registered: Dec 15 2010
Posts: 6
looks like once all the fields are selected and the user clicks submit again it dosen't go to the Email now. Nothing like java scripting headaches.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Pretty hard to see the exact problem you are having when I do not have a copy of your form. I set up a sample form with 2 check boxes and your script modified for 2 check boxes. Make sure all your field names are correctly spelled and captalized.

Do you get any error displays of any kind?

Have you opened the JS Debugging console?

Try this code for 2 check boxes only:

console.show();
console.clear();
app.alert("Start test. checkbox1: " + checkbox1.rawValue + " checkbox2: " + checkbox2.rawValue);
// see if any check box is not checked
if(checkbox1.rawValue == 0 | checkbox2.rawValue == 0){
// an unchecked box has been found
xfa.host.messageBox(" must view the terms and conditions");
} else {
// all check boxes checked
EmailSubmitButton1.execEvent("click");
}
console.show();


George Kaiser

mroiniotis01
Registered: Dec 15 2010
Posts: 6
From what i can see no errors.

I'm in life cycle and I don't see a JS debuuger

the code you modififed worked perfectly.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You can use the key combination of + "J".

George Kaiser