/    Sign up×
Community /Pin to ProfileBookmark

text field validate

i cant get this validation code to work.. can someone please help me fix it

function validateInput()
{
if ((document.user_prefs.user_name.value == “”)||(document.user_prefs.password.value == “”))
window.alert(“Name and password are required”);

else {
checkLogin();

}//end if

}//end validateInput

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 19.2004 — [code=php]
function validateInput(f){
if ((f.elements['user_name'].value.length<1)||(f.elements['password'].value.length<1))
{
window.alert("Name and password are required");
return false
}
else {
checkLogin();
}
}

...

<form onsubmit="return validateInput(this)">
...
...
<input type="submit" value="Login">
</form>
[/code]
×

Success!

Help @hisa 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.18,
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,
)...