Page 1 of 1

update username fld based on values entered in name flds

Posted: Mon Dec 02, 2002 11:29 pm
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

Posted: Fri Dec 06, 2002 8:01 am
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.