/    Sign up×
Community /Pin to ProfileBookmark

onSubmit not working

Hi

i am trying to create js validation for a html file before i submit my form for processing. However try as i might, i cant seem to activate the js function as it goes straight thru to my php. I have modified many times but still it wun work. The following is my form:

[code=html]<form name=”login” action=”loginForm.php” method=”post” onSubmit=”return checkForm()”>
Username: <input type=”text” name=”username” />
<p>Password: <input type=”password” name=”password” /></p>
<p>&nbsp;<input type=”submit” value=”Login”/>
</p>
</form>
[/code]

and this is my js function:

[CODE]<script language=”javascript”>
function checkForm(){
if (document.form.username.value == “”)
{ alert (“Enter all fields”);
return false; }
else if (document.form.password.value == “”))
{ alert(“Enter all fields”);
return false; }
return true;
}
</script>
[/CODE]

Help is much appreciated

Many thanks
Eugene

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@boskoAug 02.2007 — When you have
[CODE]document.form.username.value[/CODE]
it means that you want value from form with name 'form' and element with name 'username'. But your form has name 'login'.
Copy linkTweet thisAlerts:
@EugeneauthorAug 02.2007 — I have edited that but it still does not work.
Copy linkTweet thisAlerts:
@samanyoluAug 02.2007 — else if (document.form.password.value == "")[color=red])[/color]
×

Success!

Help @Eugene 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 5.1,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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