Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Why Does This Validation Script Skips Two Fields?
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Why Does This Validation Script Skips Two Fields?

 Post Reply Post Reply
Author
kc27 View Drop Down
New Member
New Member


Joined: 15 Jul 2011
Points: 2
Post Options Post Options   Quote kc27 Quote  Post ReplyReply Direct Link To This Post Topic: Why Does This Validation Script Skips Two Fields?
    Posted: 02 Feb 2012 at 3:57pm
I have form with a submit button on it. The submit button runs a script that checks selected fields for required data.

My form includes a combobox with multiple choices. If the user selects a specific option from that combobox, it makes three additional text fields visible, and if those fields are visible, they should be required.

If the hidden fields are visible, the validation script checks the first unhidden field, but skips the second two fields. I've reviewed the form and the script, and I don't see why the two fields are bypassed.  Specifically as shown in the script excerpt below, when fields f5, f6, and f7 are visible, the script checks f5, but skips f6 and f7 and goes straight to f8. How do I get it to also check f6 and f7?

Any help on this would be appreciated.


var correctVersion = (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0);
var m = this.getField("txt_subject"); 
var mysubject = m.value + " - Email Request Form Submission";
var cType = "Reader";
var cVersion = "< 7";
var nWarning = 1;
var cMsg1 = "This form cannot be submitted with your version of Acrobat Reader.";
var cMsg2 = "You must use Acrobat Reader version 7 or higher.";
// If Reader 6 or below is being used, display message telling user that "Email" and "Save Data" buttons don't work.
if (app.viewerType == cType && app.viewerVersion == cVersion)
app.alert(cMsg1 + cMsg2, nWarning)
else {
f1 = this.getField("txt_date");
f2 = this.getField("txt_requested by")
f3 = this.getField("txt_requested by phone");;
f4 = this.getField("cbo_functional area");
        f5 = this.getField("cbo_dmm_ad_spon");
f6 = this.getField("txt_buyer");
f7 = this.getField("txt_buyer phone");
f8 = this.getField("cbo_dmm_finan_spon");
        f9 = this.getField("tbx_coop_dmm");
f10 = this.getField("tbx_load_dmm");
f11 = this.getField("tbx_expected roi");
f12 = this.getField("txt_subject");
f13 = this.getField("txt_objective");
f14 = this.getField("txt_start date");
f15 = this.getField("cbo_am or pm");
f16 = this.getField("txt_target audience");
        if (f1.value == "")
{app.alert ('Please enter the date you are making this request".');
           if(correctVersion) f1.setFocus();}
else if (f2.value == "Person making request")
{app.alert ('The "Requested by" line cannot be blank. Please type the name of the person requesting this ad.');
           if(correctVersion) f2.setFocus();}
else if (f3.value == "Phone #")
{app.alert ('Please type the phone number of the person requesting this project.');
           if(correctVersion) f3.setFocus();}
               else if (f4.value == "Select a Functional Area")
{app.alert ('Please select a Functional Area.');
           if(correctVersion) f4.setFocus();}
                else if(f5.display == display.visible && f5.value == "Select a DMM") {
  app.alert ('Please select a DMM.');
           if(correctVersion) f5.setFocus();}
            else if (f6.display == display.visible && f6.value == "Buyer's name")
{app.alert ('Please enter the name of the Buyer.');
           if(correctVersion) f6.setFocus();}
else if (f7.display == display.visible && f7.value == "Phone #")
{app.alert ('Please type the Buyer\'s phone number.');
           if(correctVersion) f7.setFocus();}
else if (f8.value == "Select a Financial Sponsor")
{app.alert ('Please enter the financial sponsor.');
           if(correctVersion) f8.setFocus();}
                else if (f9.value == "Enter dollars or a % amount.")
{app.alert ('Please enter a dollar or percent amount for coop.');
           if(correctVersion) f9.setFocus();}
Back to Top
Sponsored Links


Back to Top
kc27 View Drop Down
New Member
New Member


Joined: 15 Jul 2011
Points: 2
Post Options Post Options   Quote kc27 Quote  Post ReplyReply Direct Link To This Post Posted: 02 Feb 2012 at 11:37pm
I put an example form here http://www.icestormcity.com/sfl/misc/form_example.pdf

If anyone can take a look and give me some advice as to why the script is failing, I would appreciate the help.

Thanks in advance for any ideas on this.
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4106
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 03 Feb 2012 at 5:39am

If you replace the variables in the line of code:

if (app.viewerType == cType && app.viewerVersion == cVersion)
 
You would have:
 
if (app.viewerType == "Reader" && app.viewerVersion == "<7")
 
You should have
 
if (app.viewerType == "Reader" && app.viewerVersion < 7)
 
The "viewerVersion" is a number and not a character string.
 
I would look at simplifying the entire process by having a logical value that accumulates the true and false results of comparisons so you are not retesting all of the comparisons and then you only need to test that one variable at the end of the test. Use a logical AND to accumulate the test results. It will only be True if all the test are True, any test with a False result will result in a False value no matter how many other test are True.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.016 seconds.