By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,693 Members | 1,799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,693 IT Pros & Developers. It's quick & easy.

Dynamically Fill and Format a texfield box based on 2 other filled texfield boxes

P: n/a
I have 3 texfield boxes

1. firstname
2. lastname
3. username

When a person enters in their firstname and lastname, I want the
username field to fill with firstnameLastinitial.

Eg. Firstname = Adam, Lastname = Apple, Username = AdamA

I want to do it dynamically so as they're typing their firstname, it's
filling in the username field. And when they fill in their lastname,
it does it, but it would only have to do it for the first letter then
go out of the loop.

I don't even know where to start on this one.. onChange is the event?
:)

Any help appreciated
Ryan
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

RelaxoRy <re******@postmaster.co.uk> wrote in message
news:3b**************************@posting.google.c om...
I have 3 texfield boxes

1. firstname
2. lastname
3. username

When a person enters in their firstname and lastname, I want the
username field to fill with firstnameLastinitial.

Eg. Firstname = Adam, Lastname = Apple, Username = AdamA

I want to do it dynamically so as they're typing their firstname, it's
filling in the username field. And when they fill in their lastname,
it does it, but it would only have to do it for the first letter then
go out of the loop.

I don't even know where to start on this one.. onChange is the event?
:)

Any help appreciated
Ryan


Hi Ryan,
sure sounds like this one has been done before somewhere.

The onchange version works when you're finsihed with a field and
could be as simple as

<form name="myform">
<table cols="1" width="200">
<tr><td>
First <input type="text" width="20" maxlength="20" value="" name="first"
onchange="myform.full.value=myform.first.value+' '+myform.last.value;"
/>
</td></tr>
<tr><td>
Last <input type="text" width="20" maxlength="20" value="" name="last"
onchange="myform.full.value=myform.first.value+' '+myform.last.value;"
/>
</td></tr>
<tr><td>
Full <input type="text" width="4" maxlength="40" value="" name="full"
READONLY />
</td></tr>
</table>
</form>

The more dynamic version may be a bit more involved and
will probably use HTMLElement.onkeypress for starters.
No example at this time.

Chris
Jul 20 '05 #2

P: n/a

"RelaxoRy" <re******@postmaster.co.uk> wrote in message
news:3b**************************@posting.google.c om...
I have 3 texfield boxes

1. firstname
2. lastname
3. username

When a person enters in their firstname and lastname, I want the
username field to fill with firstnameLastinitial.

Eg. Firstname = Adam, Lastname = Apple, Username = AdamA

I want to do it dynamically so as they're typing their firstname, it's
filling in the username field. And when they fill in their lastname,
it does it, but it would only have to do it for the first letter then
go out of the loop.

I don't even know where to start on this one.. onChange is the event?
:)

Any help appreciated
Ryan


How about this idea - using 'onkeyup'...

<html>
<head>
<title></title>
<head>
<script type="text/javascript">

function yourUserName()
{
var first = document.forms['myForm'].elements['firstname'];
var last = document.forms['myForm'].elements['lastname'];
var user = document.forms['myForm'].elements['username'];

user.value = first.value + last.value.charAt(0);
}

</script>
</head>
<body>
<form name="myForm">

<input type="text" name="firstname"
onkeyup="this.form.username.value=this.value">
<input type="text" name="lastname" onkeyup="yourUserName()">
<input type="text" name="username">

</form>
</body>
</html>

--
Geoff
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.