Little javascript help

Associate
Joined
26 Jan 2005
Posts
1,586
Location
Newcastle, UK
Hey all,

Just wondering if anyone can help me with this little form problem I have.

www.scottjs.net/test.htm

If you type in box 1 it will copy the text into box 2 as you're writing it which is what I need it to do, but it is always one character behind and I don't know how else to do it. So if I type a character, the char won't print in the other box until I press another key.

Is there another way Ican do this so when I type the first char it shows the first char in the other box straight away?

Thanks,
Scott.
 
The value of the text box isn't created until after the keypress event, so I don't believe you can use it in that way.

However, capturing the key(code) pressed when the keypress event fires does work:
Code:
function input(e) {
	var keycode = window.event ? e.keyCode : e.which;
	document.formName.textfieldName2.value += String.fromCharCode(keycode);
}
and
Code:
<input name="textfieldName" onkeypress="input(event);" type="text">
I'm sure there's a better way to do it, but my brain's running on low power at the moment.
 
Back
Top Bottom