Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JavaScript and AJAX (http://www.go4expert.com/forums/javascript/)
-   -   Binding 2 text fields and changing format (http://www.go4expert.com/forums/binding-2-text-fields-changing-format-t7458/)

zeetec1 22Nov2007 19:48

Binding 2 text fields and changing format
 
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.

pradeep 23Nov2007 10:13

Re: Binding 2 text fields and changing format
 
Yes, it's very much possible with JavaScript!

zeetec1 26Nov2007 14:26

Re: Binding 2 text fields and changing format
 
How? Please provide me some code.

Thank you.

shabbir 26Nov2007 17:24

Re: Binding 2 text fields and changing format
 
You are already doing it correctly. Is there any problem you are facing with the code.

pradeep 27Nov2007 10:19

Re: Binding 2 text fields and changing format
 
Code: 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>



All times are GMT +5.5. The time now is 13:34.