Click to See Complete Forum and Search --> : Calculating a username from first and last name input fields


dickey
12-05-2002, 06:44 PM
FYI: this is my first post to this forum.

By setting the onchange event for form text input tags name=firstname, and name=lastname to setuname() I wish to calculate a username being the first char of the firstname and first 5 chars of the lastname fields. Both input tags f and l names are text.

Basically, this javascript is incorrect. Could someone assist with the correct syntax.

<SCRIPT language="JavaScript">
function setuname ()
{
var a = Left(document.myform.firstname.value, 1);
var b = Left(document.myform.lastname.value, 5);
document.myform.username.value = a+b;
}
</SCRIPT>

Many thanks - Dickey

gil davis
12-05-2002, 07:00 PM
http://developer.netscape.com/docs/manuals/js/client/jsref/string.htm#1194618

a = document.myform.firstname.value.substr(0, 1)

gets the first character.

b = document.myform.lastname.value.substr(0, 5)

gets 5 characters.

dickey
12-05-2002, 07:59 PM
Thanks Gil