0

I need to live update a text field in html using javascript, that is as the user is typing text in one field, the contents are being displayed in another as they type. i need just a short code snippet to do that. eg as a person is typing their name, the name is being typed one letter at a time at another position on the screen.

1 Answer 1

3

Give the two fields an id each, then use something like this:

document.getElementById("field1").onkeyup = function() {
   document.getElementById("field2").value = this.value;   
}

All it does is bind an event listener to the onkeyup event, which fires every time a key is released. In the event listener, it simply copies the value of the field which received the event to another field, specified by id.

Here's a working example.

Sign up to request clarification or add additional context in comments.

1 Comment

@ThinkingStiff - Thanks, not sure how that happened! I've fixed it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.