PDA

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



dasani
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

Thanks

chump2877
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">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>Copy onBlur:</p>
<p><input type="text" onblur="copyText('tb2',this)"> <input type="text" id="tb2"></p>
<hr>
<p>Copy onKeyUp:</p>
<p><input type="text" onkeyup="copyText('tb4',this)"> <input type="text" id="tb4"></p>
</body>
<script type="text/javascript">
function copyText(id, firstTextBox)
{
document.getElementById(id).value = firstTextBox.value;
}
</script>
</html>

vwphillips
Sep 11th, 2007, 06:20 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function Repeat(source,target){
source.form[target].value=source.value;

}
/*]]>*/
</script></head>

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

</html>

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