Javascript validation works in IE but not Firefox

G

goga

Hi there,

The following simple validation code works in internet explorer but
doesn't in firefox.
Specifically, in firefox shows the alert message and then loads the
action page anyway.

Any help appreciated!!

<head>
<title>test</title>

<SCRIPT type="text/javascript" LANGUAGE="JavaScript">

function validate()
{
alert('hello');
return false;
}

</SCRIPT>

</head>


<body>

<form method="post" name="signup" ID="myform"
action="http://www.google.com">
<input type="submit" name="action" ID="myinput" value="submit"
onMouseDown="validate();" >
</form>

</body>
 
M

Martin Honnen

goga wrote:

<input type="submit" name="action" ID="myinput" value="submit"
onMouseDown="validate();" >

Use
<input type="submit"
onclick="return validate();"
 
L

Lasse Reichstein Nielsen

Martin Honnen said:
Use
<input type="submit"
onclick="return validate();"

or better yet (since it works with keyboard submission too):
<form action="..." onsubmit="return validate();">

/L
 
G

goga

Thanks guys,

the solutions worked fine, the 'return validate()' was causing me
troubles!!

Cheers
 
A

ASM

goga a écrit :
Hi there,

The following simple validation code works in internet explorer but
doesn't in firefox.
Specifically, in firefox shows the alert message and then loads the
action page anyway.

Absolutly not !
That works whith my Fx (and it is very curious)

The best way would be :

<form method="post" name="signup" ID="myform"
action="http://www.google.com"
onsubmit="return validate();">

<input type="submit" name="action" ID="myinput" value="submit">

</form>
 

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,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top