Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q476 How can I get a text entered in one text field copied in realtime to another text field?

You are here: irt.org | FAQ | JavaScript | Form | 10.1 | Q476 [ previous next ]

This is only really possible in Netscape Navigator 4 and Internet Explorer 4 with the onKeyUp event handler:

<html>

<head>
<script language="JavaScript"><!--
function copyData(from,to) { to.value = from.value; }
//--></script>
</head>
<body>

<form name="myForm">
<input type="text" name="field1"
    onChange="copyData(this,document.myForm.field2)"
    onKeyUp="copyData(this,document.myForm.field2)">
<input type="text" name="field2"
    onChange="copyData(this,document.myForm.field1)"
    onKeyUp="copyData(this,document.myForm.field1)">
</form>

</body>
</html>

With any older browser you have to wait until the onChange event is triggered, when the user moves away from the text field.

©2018 Martin Webb