Required Fields and Warning Boxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cubicle Intern

    Required Fields and Warning Boxes

    Hi,

    I have a form with multiple fields that confirmed before the form is
    submitted (ex. email field needs to be completed before the form can
    be submitted). Once the required fields are completed, I want a final
    warning box to appear asking the user "are you sure you want to make
    these changes?" I'm having trouble getting the function to work
    correctly. Here's the problem I've encountered:

    First Script: this one lets me enter an email into an empty email
    field and shows the confirmation box but the information in the form
    is updated regardless of whether I click OK or Cancel.

    function page_check()
    {
    if (check(document .form.txt_EMail .value,true))
    {
    if ((document.form .txt_EMail.valu e!="") &&
    (check(document .form.txt_EMail .value,false)))
    document.form.s ubmit();
    else
    {
    if (document.form. txt_EMail.value =='')
    alert('Please enter an email.');
    return;
    }

    if(confirm("Are you sure you want to upload this file?"))
    {
    document.form.p age_check()
    return false;
    }
    }
    }

    Second Script: When I create a separate function with "are you sure
    you..." warning similar to this:

    function page_check()
    { if(confirm("Are you sure you want to upload this file?"))
    {
    document.form.p age_check()
    return false;
    }
    }else
    return true;
    }

    it does not prompt me to complete the email field. It goes straight
    to the warning, "are you sure..." However, if I click Cancel, then it
    does not update, and if I click OK it updates.

    Any suggestions on how to fix this script so that I can keep the enter
    email prompt AND the warning prompt?

    Any help is very much appreciated. Thanks in advance.

  • tomtom.wozniak@gmail.com

    #2
    Re: Required Fields and Warning Boxes

    On Apr 15, 5:28 pm, Cubicle Intern <vyts...@gmail. comwrote:
    Hi,
    >
    I have a form with multiple fields that confirmed before the form is
    submitted (ex. email field needs to be completed before the form can
    be submitted). Once the required fields are completed, I want a final
    warning box to appear asking the user "are you sure you want to make
    these changes?" I'm having trouble getting the function to work
    correctly. Here's the problem I've encountered:
    >
    First Script: this one lets me enter an email into an empty email
    field and shows the confirmation box but the information in the form
    is updated regardless of whether I click OK or Cancel.
    >
    function page_check()
    {
    if (check(document .form.txt_EMail .value,true))
    {
    if ((document.form .txt_EMail.valu e!="") &&
    (check(document .form.txt_EMail .value,false)))
    document.form.s ubmit();
    else
    {
    if (document.form. txt_EMail.value =='')
    alert('Please enter an email.');
    return;
    }
    >
    if(confirm("Are you sure you want to upload this file?"))
    {
    document.form.p age_check()
    return false;
    }
    }
    >
    }
    >
    Second Script: When I create a separate function with "are you sure
    you..." warning similar to this:
    >
    function page_check()
    { if(confirm("Are you sure you want to upload this file?"))
    {
    document.form.p age_check()
    return false;
    }
    }else
    return true;
    >
    }
    >
    it does not prompt me to complete the email field. It goes straight
    to the warning, "are you sure..." However, if I click Cancel, then it
    does not update, and if I click OK it updates.
    >
    Any suggestions on how to fix this script so that I can keep the enter
    email prompt AND the warning prompt?
    >
    Any help is very much appreciated. Thanks in advance.
    Let me know if this is of any use. Specifically, I would access the
    form field via "document.f orms[0]" instead of "document.form" .

    Note that onSubmit wants a true or false value from the returning
    function. If onSubmit receives false, form.submit never fires (you
    don't have to explicitly submit within your function call. When
    onSubmit receives true, the current values entered in the form will be
    sent to the server.

    <html>
    <head>
    <script>
    function errorfree (initialValue,e rrorValue,msg) {
    var err = (initialValue == errorValue);
    if (err) if( msg || '' != '' ) alert (msg);
    return (! err);
    }
    </script>
    </head>
    <body>
    <form method="GET" action="" onSubmit="retur n errorfree
    (document.forms[0].txt_EMail.valu e || '','','Please enter an
    email.')">
    <input name="txt_EMail " id="txt_EMail" />
    <input type="submit" />
    </form>
    </body>
    </html>

    -Tom Woz

    Comment

    • Cubicle Intern

      #3
      Re: Required Fields and Warning Boxes

      On Apr 15, 9:19 pm, tomtom.wozn...@ gmail.com wrote:
      On Apr 15, 5:28 pm, Cubicle Intern <vyts...@gmail. comwrote:
      >
      >
      >
      >
      >
      Hi,
      >
      I have a form with multiple fields that confirmed before the form is
      submitted (ex. email field needs to be completed before the form can
      be submitted).  Once the required fields are completed, I want a final
      warning box to appear asking the user "are you sure you want to make
      these changes?"  I'm having trouble getting the function to work
      correctly.  Here's the problem I've encountered:
      >
      First Script: this one lets me enter an email into an empty email
      field and shows the confirmation box but the information in the form
      is updated regardless of whether I click OK or Cancel.
      >
      function page_check()
      {
      if (check(document .form.txt_EMail .value,true))
              {
                              if ((document.form .txt_EMail.valu e!="") &&
      (check(document .form.txt_EMail .value,false)))
                              document.form.s ubmit();
                              else
                                      {
                                              if (document.form. txt_EMail.value =='')
                                                      alert('Please enter an email.');
                                                              return;
                                      }
      >
        if(confirm("Are you sure you want to upload this file?"))
                              {
                              document.form.p age_check()
                              return false;
                              }
              }
      >
      }
      >
      Second Script: When I create a separate function with  "are you sure
      you..." warning similar to this:
      >
      function page_check()
      {  if(confirm("Are you sure you want to upload this file?"))
                              {
                              document.form.p age_check()
                              return false;
                              }
              }else
                        return true;
      >
      }
      >
       it does not prompt me to complete the email field.  It goes straight
      to the warning, "are you sure..." However, if I click Cancel, then it
      does not update, and if I click OK it updates.
      >
      Any suggestions on how to fix this script so that I can keep the enter
      email prompt AND the warning prompt?
      >
      Any help is very much appreciated.  Thanks in advance.
      >
      Let me know if this is of any use.  Specifically, I would access the
      form field via "document.f orms[0]" instead of "document.form" .
      >
      Note that onSubmit wants a true or false value from the returning
      function.  If onSubmit receives false, form.submit never fires (you
      don't have to explicitly submit within your function call.  When
      onSubmit receives true, the current values entered in the form will be
      sent to the server.
      >
      <html>
      <head>
        <script>
          function errorfree (initialValue,e rrorValue,msg) {
            var err = (initialValue == errorValue);
            if (err) if( msg || '' != '' ) alert (msg);
            return (! err);
          }
        </script>
      </head>
      <body>
        <form method="GET" action="" onSubmit="retur n errorfree
      (document.forms[0].txt_EMail.valu e || '','','Please enter an
      email.')">
          <input name="txt_EMail " id="txt_EMail" />
          <input type="submit" />
        </form>
      </body>
      </html>
      >
      -Tom Woz- Hide quoted text -
      >
      - Show quoted text -

      Hi,

      Thanks for the help but unfortunately it didn't work as well as I
      hoped it would. Would you be able to suggest how to apply multiple if/
      else statements to the function above?

      tyv


      Comment

      • Cubicle Intern

        #4
        Re: Required Fields and Warning Boxes

        On Apr 15, 9:19 pm, tomtom.wozn...@ gmail.com wrote:
        On Apr 15, 5:28 pm, Cubicle Intern <vyts...@gmail. comwrote:
        >
        >
        >
        >
        >
        Hi,
        >
        I have a form with multiple fields that confirmed before the form is
        submitted (ex. email field needs to be completed before the form can
        be submitted).  Once the required fields are completed, I want a final
        warning box to appear asking the user "are you sure you want to make
        these changes?"  I'm having trouble getting the function to work
        correctly.  Here's the problem I've encountered:
        >
        First Script: this one lets me enter an email into an empty email
        field and shows the confirmation box but the information in the form
        is updated regardless of whether I click OK or Cancel.
        >
        function page_check()
        {
        if (check(document .form.txt_EMail .value,true))
                {
                                if ((document.form .txt_EMail.valu e!="") &&
        (check(document .form.txt_EMail .value,false)))
                                document.form.s ubmit();
                                else
                                        {
                                                if (document.form. txt_EMail.value =='')
                                                        alert('Please enter an email.');
                                                                return;
                                        }
        >
          if(confirm("Are you sure you want to upload this file?"))
                                {
                                document.form.p age_check()
                                return false;
                                }
                }
        >
        }
        >
        Second Script: When I create a separate function with  "are you sure
        you..." warning similar to this:
        >
        function page_check()
        {  if(confirm("Are you sure you want to upload this file?"))
                                {
                                document.form.p age_check()
                                return false;
                                }
                }else
                          return true;
        >
        }
        >
         it does not prompt me to complete the email field.  It goes straight
        to the warning, "are you sure..." However, if I click Cancel, then it
        does not update, and if I click OK it updates.
        >
        Any suggestions on how to fix this script so that I can keep the enter
        email prompt AND the warning prompt?
        >
        Any help is very much appreciated.  Thanks in advance.
        >
        Let me know if this is of any use.  Specifically, I would access the
        form field via "document.f orms[0]" instead of "document.form" .
        >
        Note that onSubmit wants a true or false value from the returning
        function.  If onSubmit receives false, form.submit never fires (you
        don't have to explicitly submit within your function call.  When
        onSubmit receives true, the current values entered in the form will be
        sent to the server.
        >
        <html>
        <head>
          <script>
            function errorfree (initialValue,e rrorValue,msg) {
              var err = (initialValue == errorValue);
              if (err) if( msg || '' != '' ) alert (msg);
              return (! err);
            }
          </script>
        </head>
        <body>
          <form method="GET" action="" onSubmit="retur n errorfree
        (document.forms[0].txt_EMail.valu e || '','','Please enter an
        email.')">
            <input name="txt_EMail " id="txt_EMail" />
            <input type="submit" />
          </form>
        </body>
        </html>
        >
        -Tom Woz- Hide quoted text -
        >
        - Show quoted text -
        So I modified my script but whenever I click Cancel or OK it still
        updates everything in the form. Any suggestions are very much
        appreciated. This is what it looks like now:

        function page_check_pwd( )
        {
        if (check_pwd(docu ment.frm.txt_EM ail.value,true) )
        {
        if ((document.frm. txt_EMail.value !="") &&
        (check_pwd(docu ment.form.txt_E Mail.value,fals e)))
        document.form.s ubmit();
        else
        {
        if (document.frm.t xt_EMail.value= ="")
        alert('Please enter an email.');
        return false;
        }

        if(confirm("Are you sure you want to make these changes?"))
        {
        document.form.s ubmit()
        return true;
        } else
        return false;
        }
        }

        Comment

        • tomtom.wozniak@gmail.com

          #5
          Re: Required Fields and Warning Boxes

          On Apr 16, 3:44 pm, Cubicle Intern <vyts...@gmail. comwrote:
          On Apr 15, 9:19 pm, tomtom.wozn...@ gmail.com wrote:
          >
          >
          >
          On Apr 15, 5:28 pm, Cubicle Intern <vyts...@gmail. comwrote:
          >
          Hi,
          >
          I have a form with multiple fields that confirmed before the form is
          submitted (ex. email field needs to be completed before the form can
          be submitted). Once the required fields are completed, I want a final
          warning box to appear asking the user "are you sure you want to make
          these changes?" I'm having trouble getting the function to work
          correctly. Here's the problem I've encountered:
          >
          First Script: this one lets me enter an email into an empty email
          field and shows the confirmation box but the information in the form
          is updated regardless of whether I click OK or Cancel.
          >
          function page_check()
          {
          if (check(document .form.txt_EMail .value,true))
          {
          if ((document.form .txt_EMail.valu e!="") &&
          (check(document .form.txt_EMail .value,false)))
          document.form.s ubmit();
          else
          {
          if (document.form. txt_EMail.value =='')
          alert('Please enter an email.');
          return;
          }
          >
          if(confirm("Are you sure you want to upload this file?"))
          {
          document.form.p age_check()
          return false;
          }
          }
          >
          }
          >
          Second Script: When I create a separate function with "are you sure
          you..." warning similar to this:
          >
          function page_check()
          { if(confirm("Are you sure you want to upload this file?"))
          {
          document.form.p age_check()
          return false;
          }
          }else
          return true;
          >
          }
          >
          it does not prompt me to complete the email field. It goes straight
          to the warning, "are you sure..." However, if I click Cancel, then it
          does not update, and if I click OK it updates.
          >
          Any suggestions on how to fix this script so that I can keep the enter
          email prompt AND the warning prompt?
          >
          Any help is very much appreciated. Thanks in advance.
          >
          Let me know if this is of any use. Specifically, I would access the
          form field via "document.f orms[0]" instead of "document.form" .
          >
          Note that onSubmit wants a true or false value from the returning
          function. If onSubmit receives false, form.submit never fires (you
          don't have to explicitly submit within your function call. When
          onSubmit receives true, the current values entered in the form will be
          sent to the server.
          >
          <html>
          <head>
          <script>
          function errorfree (initialValue,e rrorValue,msg) {
          var err = (initialValue == errorValue);
          if (err) if( msg || '' != '' ) alert (msg);
          return (! err);
          }
          </script>
          </head>
          <body>
          <form method="GET" action="" onSubmit="retur n errorfree
          (document.forms[0].txt_EMail.valu e || '','','Please enter an
          email.')">
          <input name="txt_EMail " id="txt_EMail" />
          <input type="submit" />
          </form>
          </body>
          </html>
          >
          -Tom Woz- Hide quoted text -
          >
          - Show quoted text -
          >
          So I modified my script but whenever I click Cancel or OK it still
          updates everything in the form. Any suggestions are very much
          appreciated. This is what it looks like now:
          >
          function page_check_pwd( )
          {
          if (check_pwd(docu ment.frm.txt_EM ail.value,true) )
          {
          if ((document.frm. txt_EMail.value !="") &&
          (check_pwd(docu ment.form.txt_E Mail.value,fals e)))
          document.form.s ubmit();
          else
          {
          if (document.frm.t xt_EMail.value= ="")
          alert('Please enter an email.');
          return false;
          }
          >
          if(confirm("Are you sure you want to make these changes?"))
          {
          document.form.s ubmit()
          return true;
          } else
          return false;
          >
          }
          }
          I cleaned up your latest code. Let me know if this is what you're
          looking for.

          function page_check_pwd( ) {
          var result = false; // only set to true when validated.
          if (check_pwd(docu ment.frm.txt_EM ail.value,true) ) {
          if ((document.frm. txt_EMail.value !="") &&
          (check_pwd(docu ment.form.txt_E Mail.value,fals e))) {
          if (confirm("Are you sure you want to make these changes?")) {
          result = true;
          }
          } else {
          if (document.frm.t xt_EMail.value= ="") {
          alert('Please enter an email.');
          }
          }
          }
          return result;
          }

          -Tom Woz

          Comment

          • Cubicle Intern

            #6
            Re: Required Fields and Warning Boxes

            On Apr 17, 11:36 am, tomtom.wozn...@ gmail.com wrote:
            On Apr 16, 3:44 pm, Cubicle Intern <vyts...@gmail. comwrote:
            >
            >
            >
            >
            >
            On Apr 15, 9:19 pm, tomtom.wozn...@ gmail.com wrote:
            >
            On Apr 15, 5:28 pm, Cubicle Intern <vyts...@gmail. comwrote:
            >
            Hi,
            >
            I have a form with multiple fields that confirmed before the form is
            submitted (ex. email field needs to be completed before the form can
            be submitted).  Once the required fields are completed, I want a final
            warning box to appear asking the user "are you sure you want to make
            these changes?"  I'm having trouble getting the function to work
            correctly.  Here's the problem I've encountered:
            >
            First Script: this one lets me enter an email into an empty email
            field and shows the confirmation box but the information in the form
            is updated regardless of whether I click OK or Cancel.
            >
            function page_check()
            {
            if (check(document .form.txt_EMail .value,true))
                    {
                                    if ((document.form .txt_EMail.valu e!="") &&
            (check(document .form.txt_EMail .value,false)))
                                    document.form.s ubmit();
                                    else
                                            {
                                                    if (document.form. txt_EMail.value =='')
                                                            alert('Please enter an email.');
                                                                    return;
                                            }
            >
              if(confirm("Are you sure you want to upload this file?"))
                                    {
                                    document.form.p age_check()
                                    return false;
                                    }
                    }
            >
            }
            >
            Second Script: When I create a separate function with  "are you sure
            you..." warning similar to this:
            >
            function page_check()
            {  if(confirm("Are you sure you want to upload this file?"))
                                    {
                                    document.form.p age_check()
                                    return false;
                                    }
                    }else
                              return true;
            >
            }
            >
             it does not prompt me to complete the email field.  It goes straight
            to the warning, "are you sure..." However, if I click Cancel, then it
            does not update, and if I click OK it updates.
            >
            Any suggestions on how to fix this script so that I can keep the enter
            email prompt AND the warning prompt?
            >
            Any help is very much appreciated.  Thanks in advance.
            >
            Let me know if this is of any use.  Specifically, I would access the
            form field via "document.f orms[0]" instead of "document.form" .
            >
            Note that onSubmit wants a true or false value from the returning
            function.  If onSubmit receives false, form.submit never fires (you
            don't have to explicitly submit within your function call.  When
            onSubmit receives true, the current values entered in the form will be
            sent to the server.
            >
            <html>
            <head>
              <script>
                function errorfree (initialValue,e rrorValue,msg) {
                  var err = (initialValue == errorValue);
                  if (err) if( msg || '' != '' ) alert (msg);
                  return (! err);
                }
              </script>
            </head>
            <body>
              <form method="GET" action="" onSubmit="retur n errorfree
            (document.forms[0].txt_EMail.valu e || '','','Please enter an
            email.')">
                <input name="txt_EMail " id="txt_EMail" />
                <input type="submit" />
              </form>
            </body>
            </html>
            >
            -Tom Woz- Hide quoted text -
            >
            - Show quoted text -
            >
            So I modified my script but whenever I click Cancel or OK it still
            updates everything in the form.  Any suggestions are very much
            appreciated.  This is what it looks like now:
            >
            function page_check_pwd( )
            {
                    if (check_pwd(docu ment.frm.txt_EM ail.value,true) )
                    {
                                    if ((document.frm. txt_EMail.value !="") &&
            (check_pwd(docu ment.form.txt_E Mail.value,fals e)))
                                    document.form.s ubmit();
                                    else
                                            {
                                                    if (document.frm.t xt_EMail.value= ="")
                                                            alert('Please enter an email.');
                                                                    return false;
                                            }
            >
              if(confirm("Are you sure you want to make these changes?"))
                {
                document.form.s ubmit()
                return true;
                    } else
                    return false;
            >
            }
            }
            >
            I cleaned up your latest code.  Let me know if this is what you're
            looking for.
            >
              function page_check_pwd( ) {
                var result = false; // only set to true when validated.
                if (check_pwd(docu ment.frm.txt_EM ail.value,true) ) {
                  if ((document.frm. txt_EMail.value !="") &&
            (check_pwd(docu ment.form.txt_E Mail.value,fals e))) {
                    if (confirm("Are you sure you want to make these changes?")) {
                      result = true;
                    }
                  } else {
                    if (document.frm.t xt_EMail.value= ="") {
                      alert('Please enter an email.');
                    }
                  }
                }
                return result;
              }
            >
            -Tom Woz- Hide quoted text -
            >
            - Show quoted text -
            Hi,

            I played around with the code a little bit but I still can't get the
            warning box to work. Cancel works but when I click OK, nothing
            happens (Basically, the opposite problem from what I have before).
            Thanks for any additional help.

            tyv

            Comment

            Working...