update username fld based on values entered in name flds

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
dickey
Forum Commoner
Posts: 50
Joined: Thu May 16, 2002 8:04 pm
Location: Sydney, Australia

update username fld based on values entered in name flds

Post by dickey »

I wish to poulate a username field with the first char of the fname, and first 7 say of the lname field when entered on a form.

I have set the onchange of the fname and lname flds to be a javascript call setusername so that the username reflects changes in these fields.

Basically left(document.myform.fname.value, 1) + left(document.myform.fname.value, 7)

Just the javascript syntax I am unsure of.

Code: Select all

<SCRIPT language="JavaScript">
function setusername ()
&#123;
document.myform.username.value=?;
&#125;
</SCRIPT>

Any assistane would be appreciated.

-Dickey
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

Try this:

Code: Select all

<SCRIPT language="JavaScript"> 
function setusername () 
&#123; 
document.myform.username.value =
   substr(document.myform.fname.value, 1, 1) +
   substr(document.myform.lname.value, 1, 7) ; 
&#125; 
</SCRIPT>
I use http://www.devguru.com/Technologies/ecm ... thods.html for my reference for Javascript syntax and methods.
Post Reply