PDA

View Full Version : Form Submission Confirmation



Sicton
Apr 20th, 2005, 03:10 PM
Right, my javascript knowledge is very limited but I'm pretty sure what I'm trying to do is possible.

I have a form and when it is submitted I want an alert box to come up for the user so they can confirm the submission of the form.

If they click OK, I want the form to carry on as if they had just submitted the form normally, and if they click Cancel I want the form to not be submitted and for the user to stay where they are.

Sounds simple enough and I've searched for something that does this but none of the scripts I found do exactly this, so how do I do it?

Many thanks in advance.

jbot
Apr 20th, 2005, 03:16 PM
I've searched for something that does this but none of the scripts I found do exactly this

what have you got so far?

Sicton
Apr 20th, 2005, 03:37 PM
Something along the lines of...


function confirm_delete(){
var agree=confirm("Are you sure you wish to delete the selected comment(s)?");
if (agree){
// ???
}

jbot
Apr 20th, 2005, 03:44 PM
function confirm_delete(){
var agree=confirm("Are you sure you wish to delete the selected comment(s)?");
if (agree){
// ???
}




function confirm_delete()
{
if (confirm("Are you sure you wish to delete the selected comment(s)?")) return true;
else return false;
}

glenmac
Apr 20th, 2005, 03:50 PM
<script language="JavaScript">
function chkForm() {
return confirm("Are you sure you want to send form?");
}

</script>
...
<FORM action = "test.htm" onsubmit = "return chkForm();" >
<input id="ID00" type="text" value="00"> <br />
<input type="submit" />
</FORM>

even simpler

<FORM action = "test.htm" onsubmit = "return confirm('Are you sure you want to send form?');" >
<input id="ID00" type="text" value="00"> <br />
<input type="submit" />
</FORM>

Sicton
Apr 20th, 2005, 04:06 PM
Cheers, I didn't know it was so simple as that second option you offered - it works just perfectly.

Thanks very much :)

jbot
Apr 20th, 2005, 04:52 PM
the second option might seem simpler but it's not as extensible, meaning you couldn't reuse the same code without re-copying it everytime you wanted to use that exact same message.

Sicton
Apr 20th, 2005, 05:07 PM
Yeah, hence the benefit of using functions for portability.

In this instance I'm only using it the once but valid point worth making.