By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

Required Fields and Warning Boxes

P: n/a
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.

Jun 27 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.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
Jun 27 '08 #2

P: n/a
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.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
Jun 27 '08 #3

P: n/a
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.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;
}
}
Jun 27 '08 #4

P: n/a
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.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
Jun 27 '08 #5

P: n/a
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.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

Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.