how do I cancell a form submit in netscape or opera?

akohl's picture

They have: 117 posts

Joined: Feb 2001

How do I cancell a form submit in java script for netscape and Opera?
The following works for ie only.

function validate()
{

window.alert("your form won't be submitted")
window.event.returnValue=false
}


<form name="form1" method="post" action="page.asp" onsubmit="validate()">
'

Andy Kohlenberg
Jerusalem, Israel

akohl's picture

They have: 117 posts

Joined: Feb 2001

sorry. Should have put this into client side scripting.
Awaiting thread move!

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Just use a return, for example:

function validate()
{
// some validation code here
if (validation == "ok") {
//submit form
return true;
}
else {
window.alert("your form won't be submitted")
return false;
}
}


<form name="form1" method="post" action="page.asp" onsubmit="return validate()">
'

I just used "validation == "ok" to point out that the code would only enter there if it passed validation. You would have to put your own logic in there. I don't know if this will work in Opera, but I don't see why it shouldn't.

PJ | Are we there yet?
pjboettcher.com

akohl's picture

They have: 117 posts

Joined: Feb 2001

That works fine in both. Thanks!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.