开发者

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

开发者 https://www.devze.com 2023-03-25 18:40 出处:网络
I have created a webpage using HTML and jQuery. An开发者_StackOverflow中文版d I am using webpy framework. I have two text boxes in my html/webpage. I want to display the contents of first textbox in s

I have created a webpage using HTML and jQuery. An开发者_StackOverflow中文版d 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.


Try:

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

Regards


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消