Closed Thread Icon

Topic awaiting preservation: form validation issue (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=25133" title="Pages that link to Topic awaiting preservation: form validation issue (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: form validation issue <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 02-28-2005 18:59

For some reason, I can't seem to get this to work in Firefox 1.01. It appears to work fine in IE 6.0SP1

code:
function checkme(){
if (document.email.name.value==''){
alert ('Please enter your name');
document.email.name.focus();
return false;
}else if (document.email.email.value==''){
alert ('Please enter your email address');
document.email.email.focus();
return false;
}else if (document.email.phone.value==''){
alert ('Please enter your phone number');
document.email.phone.focus();
return false;
}else if (document.email.question.value==''){
alert ('Please enter your question');
document.email.question.focus();
return false;
}else{
return true;
}
}



I call it using

code:
<form method="post" action="/send.php" name="email" onsubmit="return checkme();">



Both browsers correctly check the fields and alert if they are empty, but only IE will submit the form when it should. Firefox just sits there and sticks it's tonque out at me. What am I doing wrong?

kuckus
Paranoid (IV) Mad Librarian

From: Glienicke
Insane since: Dec 2001

posted posted 02-28-2005 20:19

I can't say that I'm seeing anything that doesn't look right in your code, but maybe you could just give another approach a try if Firefox doesn't like this one. For example, instead of returning false or true depending on what the fields contain, try setting the form's action to "javascript:void(0)" or "/send.php". Who knows, it might just do it...

kuckus

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 02-28-2005 20:52

Programmatically?

The action is already set to /send.php, and that works fine in IE.

This is driving me nuts.

kuckus
Paranoid (IV) Mad Librarian

From: Glienicke
Insane since: Dec 2001

posted posted 02-28-2005 21:10

Completely untested... let me know if it doesn't work:

code:
function checkme(){
document.email.action = 'javascript:void(0)'; //do nothing at all unless all checks are passed
if (document.email.name.value==''){
alert ('Please enter your name');
document.email.name.focus();
}else if (document.email.email.value==''){
alert ('Please enter your email address');
document.email.email.focus();
}else if (document.email.phone.value==''){
alert ('Please enter your phone number');
document.email.phone.focus();
}else if (document.email.question.value==''){
alert ('Please enter your question');
document.email.question.focus();
}else{
document.email.action = '/send.php'; //ok, go to send.php
}
}


code:
<form method="post" action="/send.php" name="email" onsubmit="checkme();">


kuckus

(Edited by kuckus on 02-28-2005 21:14)

Nathus
Bipolar (III) Inmate

From: Minnesota
Insane since: Aug 2003

posted posted 02-28-2005 21:14

Oddly enough, it seems that the / in /send.php is what is stopping it from working. I was playing with it a bit and when i took out the / it seems to work.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 02-28-2005 21:50

Son of a b*itch!

That did it. WTF?!

Thanks for spotting that.

kuckus
Paranoid (IV) Mad Librarian

From: Glienicke
Insane since: Dec 2001

posted posted 02-28-2005 22:25

Seriously?? Too strange.

Did you give my version with the slash a go ?
Wonder what's the reason for this...

(Edited by kuckus on 02-28-2005 22:33)

Nathus
Bipolar (III) Inmate

From: Minnesota
Insane since: Aug 2003

posted posted 02-28-2005 22:40

Yours doesn't work unless you take the slash out.

I have no idea why this doesn't work and it was just dumb luck for me to figure it out. I'm thinking this is a bug.

**Ok, just tested it out on my server, and it works there with the /, I was just testing it by loading it off a file on my desktop where it didn't work with the / in. It must be a problem with running off a local file system? I have no idea.

Were you testing it on a server Pugzly? or just off the HD?

(Edited by Nathus on 02-28-2005 22:41)

shingebis
Nervous Wreck (II) Inmate

From: UK
Insane since: Aug 2004

posted posted 02-28-2005 23:26

If you're just testing it from a local file, the URL it's posting to isn't an HTTP URL, and the HTML spec says that user agent behavior for a value other than an HTTP URI is undefined. Which means that it's perfectly legal for a browser to refuse to submit the form, or submit it anyway, or turn into a chicken, or... whatever.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 03-01-2005 02:41

Ah - that makes sense. I've used a leading backslash before and it worked fine.

True enough, I was testing locally. I'll have to toss that back in and test from the server.

At least my belief that I was losing what little sanity I have has been proven wrong.

Although, now that I think of it, would "/send.php" be a URI?

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 03-01-2005 03:37

It is but it's a relative URI. Technically it's the HTTP bit of the specification (not the URI bit) that is breaking I guess.

All that being said however it would be nice if it failed a bit better than that.



.:[ Never resist a perfect moment ]:.

« BackwardsOnwards »

Show Forum Drop Down Menu