Binding 2 text fields and changing format

Discussion in 'JavaScript and AJAX' started by zeetec1, Nov 22, 2007.

  1. zeetec1

    zeetec1 New Member

    Joined:
    Nov 22, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have 2 text fields on a form, field1 and field 2.

    In field1, users enter their full name.

    So for example if someone enters Joe Bloggs in field 1, I want it to display this name as an email address in field 2 in the following format:

    Joe.Bloggs@myexample.co.uk

    Is this possible?

    I am binding the 2 text fields by using the following code:-

    <input name="input1" onkeyup="input2.value=input1.value">
    <input name="input2" onkeyup="input1.value=input2.value" +'@myexample.co.uk'>

    Thanks.
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Yes, it's very much possible with JavaScript!
     
  3. zeetec1

    zeetec1 New Member

    Joined:
    Nov 22, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    How? Please provide me some code.

    Thank you.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You are already doing it correctly. Is there any problem you are facing with the code.
     
  5. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    HTML:
    <HTML>
    <HEAD>
    <TITLE>Binding 2 text fields and changing format</TITLE>
    <script language="JavaScript">
    function addEmail(oField)
    {
    	var v = oField.value.replace(/[ ]+/,'.');
    	v = v+'@myexample.co.uk';
    
    	oField.form.elements['email'].value = v;
    }
    </script>
    </HEAD>
    
    <BODY>
    <form>
    <input type="text" name="name" onBlur="addEmail(this);"><br/>
    <input type="text" name="email"><br/>
    </form>
    </BODY>
    </HTML>
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice