2 Replies Latest reply on Jan 29, 2010 1:33 PM by informantX

    Disallow form submit if number entered is outside range

    informantX

      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:

      • 'Is 'budget' value between 1 and 100?
      • If yes, allow user to submit form.
      • If no, inform the user to enter a value within range (AND disallow form submittal).

       

      Questions:

      1. Will I use the 'within' function in an 'if' statement?
      2. The 'budget' field must be numeric?
      3. Will the script act upon the 'budget' field directly?
      4. Which event(s) should be used?

       

      Please help!

      Thanks -Sam

        • 1. Re: Disallow form submit if number entered is outside range
          Steve L Walker Level 5

          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";

               }

          }

           

          When 'visible' is selected from 'status' the 'budget' field is visible and available for entry. The exit event declares 'budget' as a mandatory field and requires a value between 1 and 100.

           

           

          // 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");

          }

           

          Steve
          • 2. Re: Disallow form submit if number entered is outside range
            informantX Level 1

            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

             

            www.serapdx.com

             

            503.445.7318