/    Sign up×
Community /Pin to ProfileBookmark

sequence of text box validation

Hi,

The following code forces the user to first fill in the given name text box and then the

family name text box. It does not and should not depend on any submit event. It will not
let the user do anything else unless those two fields are completed. The combination of
the necessary onBlur() with the focus() event makes it complicated, but it works with
the help of var GivenNameComplete.

With the onLoad=”TheForm.GivenName.focus()” event still in place would anybody know
how to modify this code so the user can choose what field to begin with?

<html>

<head>
<title>Didactics Questions For Trainers</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<script language=”JavaScript”>
<!–
var GivenNameComplete=false;

function ValiGivenName(){
if (TheForm.GivenName.value==”) {
alert(‘Please fill in your given name.’);
TheForm.GivenName.focus();
}
else{
GivenNameComplete=true
TheForm.FamilyName.focus();
}
}

function ValiFamilyName(){
if (TheForm.FamilyName.value==” && GivenNameComplete) {
alert(‘Please fill in your family name.’);
TheForm.FamilyName.focus();
}
}
//–>
</script>
</head>

<body bgcolor=”E4E4E4″ onLoad=”TheForm.GivenName.focus()”>

<form name=”TheForm” method=”post” action=”Validation.html”>
<p>Given name: <input type=”text” name=”GivenName” onBlur=”ValiGivenName()”> Family name: <input
type=”text” name=”FamilyName” onBlur=”ValiFamilyName()”> </p>
</form>
</body>
</html>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @liglin 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.2,
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,
)...