can't get working in mozilla...

E

ed

Hi, I was throwing together a quick validation thing, using Dean
Edward's addEvent code, and with the following code. I am trying to
cancel the onsubmit if there is an error. By setting e.returnValue =
false; I can get it not to submit in IE, but it always submits in
mozilla, regardless of that assignment. I'd like to know 1) why, and
2) how to fix this.

Thanks!

<script ...>
addEvent( window, 'load', function(){
var loginForm = document.getElementById("loginForm");
addEvent( loginForm, 'submit', function(e){
var one = document.getElementById("newpassword").value;
var two = document.getElementById("newpassword2").value;

if( (one.length != 0) && (one == two) ){
return true;
} else {
document.getElementById("error").style.display = "block";
if(e) {
e.returnValue = false; }
}
});
});
</script>
 
P

Peter Michaux

Hi, I was throwing together a quick validation thing, using Dean
Edward's addEvent code,

I'll assume this

http://dean.edwards.name/weblog/2005/10/add-event2/
and with the following code. I am trying to
cancel the onsubmit if there is an error. By setting e.returnValue =
false; I can get it not to submit in IE, but it always submits in
mozilla, regardless of that assignment. I'd like to know 1) why, and
2) how to fix this.

Thanks!

<script ...>
addEvent( window, 'load', function(){
var loginForm = document.getElementById("loginForm");
addEvent( loginForm, 'submit', function(e){
var one = document.getElementById("newpassword").value;
var two = document.getElementById("newpassword2").value;

if( (one.length != 0) && (one == two) ){
return true;
} else {
document.getElementById("error").style.display = "block";
if(e) {
e.returnValue = false; }
}
});
});
</script>

Where you write

e.returnValue = false;

write

e.preventDefault();

This is one of the things his library fixes.

Peter
 
E

ed

Hi, I was throwing together a quick validation thing, using Dean
Edward's addEvent code, and with the following code. I am trying to
cancel the onsubmit if there is an error. By setting e.returnValue =
false; I can get it not to submit in IE, but it always submits in
mozilla, regardless of that assignment. I'd like to know 1) why, and
2) how to fix this.

Thanks!

<script ...>
addEvent( window, 'load', function(){
var loginForm = document.getElementById("loginForm");
addEvent( loginForm, 'submit', function(e){
var one = document.getElementById("newpassword").value;
var two = document.getElementById("newpassword2").value;

if( (one.length != 0) && (one == two) ){
return true;
} else {
document.getElementById("error").style.display = "block";
if(e) {
e.returnValue = false; }
}
});
});
</script>

Nevermind, got it. Didn't realize mozilla had preventDefault().
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top