/    Sign up×
Community /Pin to ProfileBookmark

validating form fields / warning message if blank

How do I validate that the values are not left blank? One is a simple form value and the other is generated by a calculation.

[CODE]//I need to validate that these form values are not blank prior to submission of the form
<form id=”sendit” action=”http://ntsacom.homestead.com/TEST3.html” method=”get”>
Player Name: <input name=”PLAYER_NAME” />
<br/>
<br/>
<div id=”age” style=”visibility: hidden;”>
League Age:<input name=”league_age” readonly />
</div>
<input type=”submit” value=”Submit this player” />

[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@WolfShadeJan 27.2012 — [CODE]
function noBlanks() { // I'll also set it to check and make sure the second value is an integer
df = document.sendit;
warn = "";
if(df.PLAYER_NAME.value.length == 0) { warn += "Please enter Player Name.n"; }
if(df.league_age.value.length == 0) { warn += "Age is empty.n"; }
else { if(isNaN(df.league_age.value)) { warn += "Age is not a number.n"; }

if(warn != "") { alert(warn); return false; }
else { return true; }

}
[/CODE]

[code=html]
<form id="sendit" action="http://ntsacom.homestead.com/TEST3.html" method="get" onSubmit = "return noBlanks();">
Player Name: <input name="PLAYER_NAME" />
<br/>
<br/>
<div id="age" style="visibility: hidden;">
League Age:<input name="league_age" readonly />
</div>
<input type="submit" value="Submit this player" />
[/code]
Copy linkTweet thisAlerts:
@BaseballauthorJan 27.2012 — I placed te html in but I am not sure where to put the code? This is the host page. http://ntsacom.homestead.com/calculator-TEST1.html
Copy linkTweet thisAlerts:
@WolfShadeJan 27.2012 — The JavaScript goes in between

[COLOR="Blue"]<script type="text/javascript">[/COLOR]

and

[COLOR="Blue"]</script>[/COLOR]

tags. This should be nested inside the <head></head> tags.
×

Success!

Help @Baseball 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.27,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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