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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

confirm 2

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
How can I have it when someone cancels a confirm to not submit a form but when they say ok - then submit it?

I have an onsubmit function that calls the confirm but it submits it either way...

thanks

[conehead]
 
I think onsubmit would execute as soon as the submission was taking place, you have to intercept it before that, maybe use onclick and have code in there to check the status of the confirmation object and then submit directly from that function.

I am assuming you have some sort of check box to confirm a form and then a submit button? You could also possibly have it so that when the confirm is canceled, the submit button disappears/is disabled like with TOS when you install software.

Jaa.
 
You need to return the boolean value that the confirm box retuns in the onsubmit handler, like this:
Code:
onsubmit='[b]return[/b](confirm("Do you want to submit"))'

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
hmmm... perhaps I am doing something wrong... I am calling a validation function via onsubmit="return check();"

the function looks like"

Code:
function check() {
	if (document.all.forma.severity.value == "") {
		alert("Please select a severity.");
		document.all.forma.severity.focus();
		return false;
	} else if (document.all.forma.emailNotify.value != "") {
		confirm("Are you sure you wish to send an email to the email list?");
	}
}

but it still submits no matter what I pick....

[conehead]
 
document.all is ie. When run on nn/ff, it go strick to after if statement where nothing is specified for return. Effectively, it is
[tt] return undefined[/tt]
So I would predict that for nn/ff, it will submit no matter what.

For ie, in else if you have all the same to put return keyword there.
[tt]
} else if (document.all.forma.emailNotify.value != "") {
[red]return[/red] confirm("Are you sure you wish to send an email to the email list?");
[/tt]
- tsuji
 
If forma is the name of the form containing the element named emailNotify, then simply put
[tt]
document.forma.severity.value
document.forma.emailNotify.value
[tt]
at their corresponding place.

- tsuji
 
It's no problem at all, really.

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
someone's feeling left out - there you go... a star for you - a startr for all for it is a friday of a three day weekend!

[conehead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top