Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple Javascript Snippet needed!

    Hi there,

    I'm coding a webapp which has a user system where admins can add or edit users. Nothing out of the ordinary.

    I have a form which looks like this:

    Code:
    <form method="POST">
    <input type="text" name="firstname" />
    <input type="text" name="lastname" />
    <input type="text" name="username" />
    When the user focuses the username field, I would like the firstname and lastname inserted.


    For example, firstname=James lastname=H, in username it would be jamesh (converted to lowercase also).

    Can you guys help me?


    Thanks very much!

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    one rough e.g.

    Code:
    <script type="text/javascript">
    
    	function setUsername() {
    
    		var fname = document.getElementById('firstname');
    		var lname = document.getElementById('lastname');
    		var uname = document.getElementById('username');
    
    		if (fname.value != '' && lname.value != '') {
    			uname.value = (fname.value+lname.value).toLowerCase();
    		}
    
    	}
    
    </script>
    
    ...
    
    <input type="text" name="firstname" id="firstname" />
    <input type="text" name="lastname" id="lastname" />
    <input type="text" name="username" id="username" onfocus="setUsername();" />
    Last edited by Bill Posters; 05-10-2007 at 11:30 AM.

  • #3
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. I had to tweak it a little, but still a great example.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •