Hi. Newbie here.
I have a form with a 'budget' field that is hidden unless the user chooses a specified value in a field called 'status.' When visible, the 'budget' field is mandatory.
The script for the above works fine, but in addition to being mandatory when visible, the 'budget' field must only accept values within a range of, say, between 1 and 100.
I can't figure out how to script the following:
Questions:
Please help!
Thanks -Sam
Views
Replies
Total Likes
Sam,
The attached form demonstrates a common technique for doing form validation on submission. The form contains a drop-down called 'status' which controls the visibility of a field called 'budget'.
// form1.page1.subform1.status::exit - (JavaScript, client)
if (form1.page1.subform1.status.rawValue == "visible") {
form1.page1.subform1.budget.presence = "visible";
}
else {
if (form1.page1.subform1.status.rawValue == "hidden") {
form1.page1.subform1.budget.presence = "hidden";
}
}
// form1.page1.subform1.budget::exit - (JavaScript, client)
if (form1.page1.subform1.budget.isNull) {
xfa.host.messageBox("Budget is a mandatory field when status is 'visible'.");
}
else {
if (form1.page1.subform1.budget.rawValue < 1 || form1.page1.subform1.budget.rawValue > 100) {
xfa.host.messageBox("The budget value must be between $1 and $100.");
}
}
The 'submitBtn' then validates both 'status' and 'budget'. The 'submitBtn' is just a regular button that enables form validation to be executed before calling the field 'hiddenSubmitBtn'. In my example 'hiddenSubmitBtn' is just a regular button that causes a message box to open demonstrating the button has been clicked by calling 'execEvent("click")'. In your case 'hiddenSubmitBtn' would be a button of type 'submit' attached to a URL.
// form1.page1.subform1.submitBtn::click - (JavaScript, client)
if (form1.page1.subform1.status.rawValue == "visible") {
if (form1.page1.subform1.budget.isNull) {
xfa.host.messageBox("Budget is a mandatory field when status is 'visible'.");
}
else {
if (form1.page1.subform1.budget.rawValue < 1 || form1.page1.subform1.budget.rawValue > 100) {
xfa.host.messageBox("The budget value must be between $1 and $100.");
}
else {
form1.page1.subform1.hiddenSubmitBtn.execEvent("click");
}
}
}
else {
form1.page1.subform1.hiddenSubmitBtn.execEvent("click");
}
Views
Replies
Total Likes
Steve,
Thanks, this is very helpful.
BTW, I'm using FormCalc. And, the 'submit' button is the stock 'Email Submit Button' from the library.
I can successfully evaluate the entry and produce warning messages, but I haven't nailed down how to prevent the form being submitted.
When the user clicks OK to the warning, the form is 'submitted' (email opens with XML file attached).
The only script I am familiar with that prevents form submission is:
Syntax.mandatory = “error”
Can I somehow incorporate the input out of range text with the mandatory error?
Or is there some other script that will work to prevent the form from being submitted by email?
Thx -Sam
Sam Easley
503.445.7318
Views
Replies
Total Likes