View Full Version : simultaneously populating the text in two text fields

Sep 11th, 2007, 05:52 PM
Hi ,

I have two text boxes in a form which contains same text 99% of time.

So i want to populate the second text field automatically when entering text in the first text field.
And also the second text field must be editable if i want to enter different text.

Plz suggest with sample code


Sep 11th, 2007, 06:16 PM
A couple different ways of approaching this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<p>Copy onBlur:</p>
<p><input type="text" onblur="copyText('tb2',this)"> <input type="text" id="tb2"></p>
<p>Copy onKeyUp:</p>
<p><input type="text" onkeyup="copyText('tb4',this)"> <input type="text" id="tb4"></p>
<script type="text/javascript">
function copyText(id, firstTextBox)
document.getElementById(id).value = firstTextBox.value;

Sep 11th, 2007, 06:20 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<script language="JavaScript" type="text/javascript">

function Repeat(source,target){


<form >
<input type="text" onkeyup="Repeat(this,'fred');" onblur="Repeat(this,'fred');" />
<input name="fred" type="text" />


Sep 11th, 2007, 07:51 PM
Thankyou for your replies.