/    Sign up×
Community /Pin to ProfileBookmark

HTML Form Validation & Masking

I’m looking for a JavaScript that will allow me to do the following:

1) Input field #1 Firstname – Force first letter to be Caps
Input field #2 Lastname – Same as above

2) From the two fields above, build the value of the next field #3
Input field #3 Login Id – Lastname+First Initial of Firstname

User Enters: jim s/b Jim
shoe s/b Shoe

Value for #3 shoej s/b ShoeJ

Hopefullly someone has a .js already, but I haven’t found it yet?

Thanks
RCG

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@marcusamiApr 30.2008 — you need to do some research on your own and try to figure it out

but this will do that exactly

[code=html]
<html>
<head>
<title>
</title>
<script language="JavaScript" type="text/javascript">
<!--
var grabInitial;

function doFirstName(){
var fName = document.getElementById('firstName').value;
var revisedF ="";
var mySplitResult = fName.split("");
var aCounter =0;
for(i = 0; i < mySplitResult.length; i++){
if(aCounter == 0){
mySplitResult[i] = mySplitResult[i].toUpperCase();
revisedF = revisedF + mySplitResult[i];
grabInitial = mySplitResult[i];
aCounter = 1;
}else{
revisedF = revisedF + mySplitResult[i];
}
}document.getElementById('firstName').value = revisedF;
}

function doLastName(){
var lName = document.getElementById('lastName').value;
var revisedL ="";
var mySplitResulta = lName.split("");
var aCountera =0;
for(i = 0; i < mySplitResulta.length; i++){
if(aCountera == 0){
mySplitResulta[i] = mySplitResulta[i].toUpperCase();
revisedL = revisedL + mySplitResulta[i];
//document.write("<br /> " + revisedName);
aCountera = 1;
}else{
revisedL = revisedL + mySplitResulta[i];
//document.write("<br /> " + revisedName);
}
}document.getElementById('lastName').value = revisedL;
document.getElementById('userName').value = revisedL + grabInitial;
}


//-->
</script>

</head>
<body>
<form>
First Name
<input type="text" name="firstName" id="firstName" onchange="doFirstName()" /><br/>
Last Name
<input type="text" name="lastName" id="lastName" onchange="doLastName()" /><br/>
User Name
<input type="text" name="userName" id="userName" /><br />
<input type="submit" value="Submit" />
</form>


</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@RCGriffithauthorApr 30.2008 — Thanks, that works just fine for me!

RCG
×

Success!

Help @RCGriffith 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.25,
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,
)...