Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine text fields

Status
Not open for further replies.

Killborg

Technical User
Jul 16, 2007
46
US
Hello,
Can anyone help with this. I am trying to combine 2 text fields into 1 text field. I found this which works when you select the button. But I do not want the function to happen when the button is selected. I want the function to occur when the person finishing entering the information in Last Name field.


<p><form name="Form1">
<br>
<tt>First Name:</tt> <input name="FirstName">
<br>
<br>
<tt>Last Name:</tt> <input name="LastName">
<p><tt>Phone Number :</tt>
<input name="Phone Number" id="Phone Number">
</p>
<p><tt>Email Address :</tt>
<input name="Email Address" id="Email Address">
</p>
<p> <tt>realname:</tt>
<input name="realname" readonly="true">
</p>
<p><br>
<input type="button" value="Combine Strings"
OnClick="realname.value= FirstName.value + ' ' + LastName.value;"></p>
</form>
 
Use
Code:
unblur="realname.value= FirstName.value + ' ' + LastName.value;"

within both FirstName and LastName fields.

That should do it!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
2 things:

- 'unblur' in SouthBeach's example should be 'onblur'.

- Don't use shortcuts to refer to your field names. Change this syntax:

Code:
xxx.value

to any proper locator, e.g. this:

Code:
this.form.xxx.value

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks Southbeach and Billyray
That worked
 
you can also use onfocus instead of blur on button, so when the focus gets on realname field, it's populated automatically:
Code:
<p><form name="Form1">
  <br>
 <tt>First Name:</tt> <input name="FirstName">
 <br>
 <br>
 <tt>Last Name:</tt> <input name="LastName"> 
 <p><tt>Phone Number :</tt>
   <input name="Phone Number" id="Phone Number">
   </p>
 <p><tt>Email Address :</tt>
    <input name="Email Address" id="Email Address">
 </p>
 <p>     <tt>realname:</tt>
    <input name="realname" readonly="true"
OnFocus="realname.value= FirstName.value + ' ' + LastName.value;">
  </p>
  
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top