/    Sign up×
Community /Pin to ProfileBookmark

onSubmit function working in IE but not FF

No matter what I put in the fields FF always returns false. In other words I always get the alert box. Is there something different about coding for FF.
Thanks
JM

Here is the script:

<?xml version=”1.0″ encoding=”iso-8859-1″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<title>Validator</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<script type=”text/javascript”>
<!–
[B]function checkForm(form)
{
for (var i = 0; i < form.elements.length; i++)
{
if (form.elements[i].value == “”)
{
alert(“Fill out ALL fields.”);
return false;
}
}
return true;
}
[/B]

//–>
</script>
</head>

<body>
[B]<form onsubmit=”return checkForm(this)” />
Please enter all requested information:<br />
First Name:<input type=”text” name=”firstName” /><br />
Last Name:<input type=”text” name=”lastName” /><br />
Rank:<input type=”text” name=”rank” /><br />
Serial Number:<input type=”text” name=”serialNumber” /><br />
<input type=”submit” />
</form>[/B]

</body>
</html>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@jmachineauthorOct 18.2005 — [code=html]
<code>
function checkForm(form)
{
for (var i = 0; i < form.elements.length; i++)
{
if (form.elements[i].value == "")
{
alert("Fill out ALL fields.");
return false;
}
}
return true;
}

<form onsubmit="return checkForm(this)" />
Please enter all requested information:<br />
First Name:<input type="text" name="firstName" /><br />
Last Name:<input type="text" name="lastName" /><br />
Rank:<input type="text" name="rank" /><br />
Serial Number:<input type="text" name="serialNumber" /><br />
<input type="submit" />
</form>

</code>


[/code]
Copy linkTweet thisAlerts:
@KravvitzOct 18.2005 — You have a rogue slash.
&lt;form onsubmit="return checkForm(this)" [b]/[/b]&gt;

The function is acting correctly in Firefox, because you didn't give the submit button a value.
Copy linkTweet thisAlerts:
@jmachineauthorOct 19.2005 — Thank you. Just learning. It seems FF is more picky which is good.

JM
×

Success!

Help @jmachine spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...