Forum Moderators: open
For example, in your text box, you have onChange="JavaScript:UpdateTheOtherBox()"
Then, when you have finished typing in the text box and tab or click out of it, it calls a function that looks like this:
function UpdateTheOtherBox()
{
document.frmForm.textBox2.value = document.frmForm.textBox1.value
}
This may not be exactly right, but should give you the idea.
-Moz
Note you would need different scripts for the Mozilla and IE event models.
I tried several event, and onKeyUp seems to be working. Try this out, and let me know what you think:
<html>
<head>
<script language="javascript">
function ChangeOtherBox()
{
document.frmForm.Box2.value = document.frmForm.Box1.value
}
</script>
</head>
<body>
<form name="frmForm">
<input type="text" name="Box1" onKeyUp="javaScript:ChangeOtherBox()">
<input type="text" name="Box2">
</form>
</body>
</html>
I agree with MozMan on the onKeyUp() event.
Here is some code to capture the actual key stroke (if you don't already have such...)
<script type="text/javascript">
<!--
function pressKey(e){
if(typeof event!='undefined'){
var pressedKey=window.event.keyCode
}else{
var pressedKey=e.keyCode
}
alert('The "'+(String.fromCharCode(pressedKey))+'" key was pressed')
}
//-->
</script>
</head>
<body>
<form>
<input type="text" size="30" value="" onkeyup="pressKey()" />
</form>
</body>
ajkimoto
You are partially correct. I neglected to add the appropriate event listener for it to work in Mozilla, though it works in IE as is. To add cross-browser compatibility, you would need to add the following to the script area:
document.addEventListener("keyup",pressKey,true);
This captures the keyup event and passes it on to the pressKey function.
ajkimoto