Jinesh
Jinesh

Reputation: 2575

Updating one text box as text is typed in another text box, using jQuery

I have created a webpage using HTML and jQuery. And I am using webpy framework. I have two text boxes in my html/webpage. I want to display the contents of first textbox in second textbox meanwhile I type in first textbox. How can I implement this using jQuery.

Upvotes: 1

Views: 597

Answers (2)

Rob Quincey
Rob Quincey

Reputation: 2896

Use jQuerys Change event handler (search for jQuery Change for full docs)

Something like this should be what you are after

$(function() {
    $('#txtbox1').change(function() {
       $('#txtbox2').val(this.value);
    });
});

EDIT - Even though this was accepted answer check out the answer provided by @Huske for a better way, both work but I thought I should point out his alternative.

Upvotes: 0

Huske
Huske

Reputation: 9296

Try:

$("#sourceText").keyup(function () {
    $("#destinationText").val($(this).val());
});

Regards

Upvotes: 3

Related Questions