onclick together with input type =submit

O

Obscurr

hi,

I've got a submit button, and when one clicks it, I want a confirm box
to pop up to make sure the user really wants that. The user is
supposed to be redirected to another url if he presses OK, and do
nothing if not. The way it works at the moment, is that the confirmbox
appears as it should, but whatever the user presses, the php code
continues to run. Any suggestions?

php:

echo "<INPUT type =\"submit\" name =\"test\"
ONCLICK=\"decision('sure?')\" value =\"Slett messe!\">
</TD></TR></form></table><br>";
function decision(message){
if (confirm(message)) window.location.href='http://www.vg.no';
}

obscurr
 
D

Daniel

Obscurr said:
hi,

I've got a submit button, and when one clicks it, I want a confirm box
to pop up to make sure the user really wants that. The user is
supposed to be redirected to another url if he presses OK, and do
nothing if not. The way it works at the moment, is that the confirmbox
appears as it should, but whatever the user presses, the php code
continues to run. Any suggestions?

You could replace the "submit" button with a "button" button and put

onClick="if (confirm('Really submit?')) { this.form.submit(); }"

that might work?
 
D

Daniel

Obscurr said:
hi,

I've got a submit button, and when one clicks it, I want a confirm box
to pop up to make sure the user really wants that. The user is
supposed to be redirected to another url if he presses OK, and do
nothing if not. The way it works at the moment, is that the confirmbox
appears as it should, but whatever the user presses, the php code
continues to run. Any suggestions?

You could replace the "submit" button with a "button" button and put

onClick="if (confirm('Really submit?')) { this.form.submit(); }"

that might work?
 
M

Martin Honnen

Obscurr said:
hi,

I've got a submit button, and when one clicks it, I want a confirm box
to pop up to make sure the user really wants that. The user is
supposed to be redirected to another url if he presses OK, and do
nothing if not. The way it works at the moment, is that the confirmbox
appears as it should, but whatever the user presses, the php code
continues to run. Any suggestions?

php:

echo "<INPUT type =\"submit\" name =\"test\"
ONCLICK=\"decision('sure?')\" value =\"Slett messe!\">
</TD></TR></form></table><br>";
function decision(message){
if (confirm(message)) window.location.href='http://www.vg.no';
}

If you want to submit a form use
<form action="whatever.php" ...>
...
<input type="submit"
onclick="return confirm('Are you sure you want to submit the
form?');">
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top