Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancel Submit, Return to Form 2

Status
Not open for further replies.

Fris

Programmer
Jun 23, 2003
22
US
Greetings!

I want to allow users to back out of submitting their form. I have included the following script

f.submit();
return confirm('Submit form?');

This works BUT if the CANCEL button is clicked, the form is submitted anyway. What am I missing?

Thanks!
Christine
 
you should put the return confirm('Submit form?');

in the onsubmit event of your form...

<form onsubmit='return(confirm(&quot;Submit form?&quot;);' ...

That should work...

 
At first glance, that seemed simple enough, however, when this form is submitted, the contents are emailed, using this code:


<form action=&quot; method=&quot;post&quot; onSubmit=&quot;Validate();&quot; id=&quot;form1&quot; name=&quot;form1&quot;>
<input type=&quot;hidden&quot; name=&quot;fcount&quot; value=&quot;24&quot;><input type=&quot;hidden&quot; name=&quot;thanksurl&quot; value=&quot; type=&quot;hidden&quot; name=&quot;recipient&quot; value=&quot;cshel@MyCompany.com&quot;>

The submit statement is at the end of a lengthy validation process. How do I incorporate your suggestion into this?

I DO have the following for the Submit button:

<input type=&quot;Submit&quot; name = &quot;Submit&quot; value=&quot;Request Written Proposal&quot; >

Thanks again!
 
show your validate function... if this doesn't work

but you should change your onsubmit to be...

onSubmit=&quot;return Validate();&quot;

make sure your Validate function returns false if you don't want the page to sumbit... good luck
 
Thank you for your help with this. I think I just about have it! I am now prompted with a box with OK/Cancel buttons. When Cancel is clicked, another box pops up that simply says &quot;false&quot; and contains OK/Cancel buttons. When Cancel is clicked, I'm returned to the form. Great! But, how to eliminate the &quot;false&quot; box. :)

The code is:

return confirm('Are you sure you want to submit this form?');
return false;

Thanks again in advance!
 
I continue to have difficulty with this step and I'm sure there's a way to do it. If at all possible, I don't want the user of this form to see anything other than the box &quot;Submit Form?&quot;. Here is part of my code, maybe someone could take a look and tell me where I need to put &quot;return confirm&quot; and the alert &quot;Submit Form?&quot; I've taken out the &quot;return confirm&quot; statment and alert, since no matter where I put them, I can't get it to work. I have tried:

onSubmit= return(confirm(Validate()));, but then I get a box that says &quot;object undefined&quot;.


function Validate()
{
f = document.form1

if ( f.FName.value == &quot;&quot;) {
alert('Please enter your First Name.')
event.returnValue=false;
return;
More validation goes here then:
{
f.submit();
}
}
// done hiding code-->
</script>
</HEAD>
<BODY>
<TR>
<form action=&quot; method=&quot;post&quot; onSubmit=Validate(); id=&quot;form1&quot; name=&quot;form1&quot;>
<input type=&quot;hidden&quot; name=&quot;fcount&quot; value=&quot;24&quot;><input type=&quot;hidden&quot; name=&quot;thanksurl&quot; value=&quot; type=&quot;hidden&quot; name=&quot;recipient&quot; value=&quot;cs@MyCompany.com&quot;>
<input type=&quot;hidden&quot; name=&quot;subject&quot; value=&quot;Name of Form&quot;>
</TR>

Lots more code, then:

<TD> <input type=&quot;Submit&quot; name = &quot;Submit&quot; value=&quot;Request Written Proposal&quot; >

Thanks again in advance for your time and efforts.

Christine
 
forget the event.returnValue=false;


change to onsubmit='return validate()'

and then just return false from your validate function if your validation fails
 
Okay...I got rid of the event.returnValue=false and replaced with return false

I revised to: onSubmit='return Validate()'

Now when I click the Submit button, the validations work, but then the form gets sent.

How do I make it stop and ask: &quot;Submit Form?&quot;.
 
Look I have no clue what you have messed up... but here is a working simple example...
--------------------------------------------------------

<html>
<head>
<script>
function validate(ths){
if (ths.silly.value.toLowerCase() != &quot;no&quot;){
alert(&quot;I said NO!!!!&quot;);
return false;
}
}
</script>
</head>
<body>
<form method='get' onsubmit='return validate(this)'>
type no in the box
<input type='text' name='silly'>
<BR><BR>
<input type='submit'>
</forM>


</form>
</body>
</html>
 
one more example
---------------------------------
<html>
<head>
<script>
function validate(){
return confirm(&quot;Are you sure you want to submit?&quot;)
}
</script>
</head>
<body>
<form method='get' onsubmit='return validate()'>
<input type='hidden' name='stuffForQuerystring' value='asdlfjalskdflaskjdfkasdf'>
Click the submit button
<input type='submit'>
</forM>


</form>
</body>
</html>
 
Good morning, jsobo!

Thank you so much for your patience with me on this. I finally got it to work. Everything you told me to do, I had done, so I deleted all validation except for the &quot;Submit Form?&quot; code. I added it back a piece at time and found out it was some mis-coding in the validation of the email. All is now well! Thank you again for sticking with me!

Christine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top