Click to See Complete Forum and Search --> : Onsubmit & "onchange=submit" in same form ...


Ash
10-27-2003, 06:02 AM
Hi,

I've got a simple function that double-checks with the user:


function quick_confirm() {
var agree=confirm("Are you sure you wish to continue?");
if (agree) return true ;
else return false ;
}

Then I've got a form with a SELECT that submits onchange.


<form method="post" action="change_accomm.php" onsubmit="quick_confirm()">
<select name="accomm_id" onchange="submit(this)">


I thought that this would call 'quick_confirm' when submit was called (ie when 'accomm_id' is changed) but it just submits the form and bypasses the 'quick_confirm' function completely!

Any ideas on what I'm doing wrong ?

Many thanks,
Ash

gil davis
10-27-2003, 08:23 AM
According to http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onsubmit.asp
The submit method does not invoke the onsubmit event handler.

Ash
10-27-2003, 08:50 AM
Hmm ... I kinda guessed as much :(

Do you know a way that I can get around this? I don't really want to slap a big ol' submit button on this page ...

Charles
10-27-2003, 01:12 PM
<select name="accomm_id" onchange="this.form.onsubmit(); submit(this)">

But be certain to use the NOSCRIPT element to provide that big old submit button for the 13% of users who do not use JavaScript

Ash
10-28-2003, 03:31 AM
This is as far as I got ...

Using this, it calls the quick_confirm (the onsubmit event) but then calls submit() regardless of the outcome of quick_confirm.

In other words, you can click 'cancel' in quick_confirm and it still submits ... :(

Charles
10-28-2003, 05:38 AM
Oops.

<select name="accomm_id" onchange="if (this.form.onsubmit()) this.form.submit()">

Ash
10-28-2003, 05:44 AM
heh-heh, that's the fella !

Thanks Charles, you're a star!