Required Fields and Warning Boxes

C

Cubicle Intern

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.value!="") &&
(check(document.form.txt_EMail.value,false)))
document.form.submit();
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.page_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.page_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.
 
T

tomtom.wozniak

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.value!="") &&
(check(document.form.txt_EMail.value,false)))
document.form.submit();
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.page_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.page_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.forms[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,errorValue,msg) {
var err = (initialValue == errorValue);
if (err) if( msg || '' != '' ) alert (msg);
return (! err);
}
</script>
</head>
<body>
<form method="GET" action="" onSubmit="return errorfree
(document.forms[0].txt_EMail.value || '','','Please enter an
email.')">
<input name="txt_EMail" id="txt_EMail" />
<input type="submit" />
</form>
</body>
</html>

-Tom Woz
 
C

Cubicle Intern

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.value!="") &&
(check(document.form.txt_EMail.value,false)))
                        document.form.submit();
                        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.page_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.page_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.forms[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,errorValue,msg) {
      var err = (initialValue == errorValue);
      if (err) if( msg || '' != '' ) alert (msg);
      return (! err);
    }
  </script>
</head>
<body>
  <form method="GET" action="" onSubmit="return errorfree
(document.forms[0].txt_EMail.value || '','','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
 
C

Cubicle Intern

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.value!="") &&
(check(document.form.txt_EMail.value,false)))
                        document.form.submit();
                        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.page_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.page_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.forms[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,errorValue,msg) {
      var err = (initialValue == errorValue);
      if (err) if( msg || '' != '' ) alert (msg);
      return (! err);
    }
  </script>
</head>
<body>
  <form method="GET" action="" onSubmit="return errorfree
(document.forms[0].txt_EMail.value || '','','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(document.frm.txt_EMail.value,true))
{
if ((document.frm.txt_EMail.value!="") &&
(check_pwd(document.form.txt_EMail.value,false)))
document.form.submit();
else
{
if (document.frm.txt_EMail.value=="")
alert('Please enter an email.');
return false;
}

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

tomtom.wozniak

Let me know if this is of any use. Specifically, I would access the
form field via "document.forms[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,errorValue,msg) {
var err = (initialValue == errorValue);
if (err) if( msg || '' != '' ) alert (msg);
return (! err);
}
</script>
</head>
<body>
<form method="GET" action="" onSubmit="return errorfree
(document.forms[0].txt_EMail.value || '','','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(document.frm.txt_EMail.value,true))
{
if ((document.frm.txt_EMail.value!="") &&
(check_pwd(document.form.txt_EMail.value,false)))
document.form.submit();
else
{
if (document.frm.txt_EMail.value=="")
alert('Please enter an email.');
return false;
}

if(confirm("Are you sure you want to make these changes?"))
{
document.form.submit()
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(document.frm.txt_EMail.value,true)) {
if ((document.frm.txt_EMail.value!="") &&
(check_pwd(document.form.txt_EMail.value,false))) {
if (confirm("Are you sure you want to make these changes?")) {
result = true;
}
} else {
if (document.frm.txt_EMail.value=="") {
alert('Please enter an email.');
}
}
}
return result;
}

-Tom Woz
 
C

Cubicle Intern

On Apr 15, 9:19 pm, (e-mail address removed) wrote:
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.value!="") &&
(check(document.form.txt_EMail.value,false)))
                        document.form.submit();
                        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.page_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.page_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.forms[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,errorValue,msg) {
      var err = (initialValue == errorValue);
      if (err) if( msg || '' != '' ) alert (msg);
      return (! err);
    }
  </script>
</head>
<body>
  <form method="GET" action="" onSubmit="return errorfree
(document.forms[0].txt_EMail.value || '','','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(document.frm.txt_EMail.value,true))
        {
                        if ((document.frm.txt_EMail.value!="") &&
(check_pwd(document.form.txt_EMail.value,false)))
                        document.form.submit();
                        else
                                {
                                        if (document.frm.txt_EMail.value=="")
                                                alert('Please enter an email.');
                                                        return false;
                                }
  if(confirm("Are you sure you want to make these changes?"))
    {
    document.form.submit()
    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(document.frm.txt_EMail.value,true)) {
      if ((document.frm.txt_EMail.value!="") &&
(check_pwd(document.form.txt_EMail.value,false))) {
        if (confirm("Are you sure you want to make these changes?")) {
          result = true;
        }
      } else {
        if (document.frm.txt_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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top