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

R

RelaxoRy

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
 
G

Geoff Tucker

RelaxoRy said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top