开发者

Jquery how to - asp.net textbox change updates another textbox

i have 2 asp.net textboxes on a page. using jquery how can i update the text of the second one when the first one changes. Has to be jquery using asp.net textboxes

e.g. as user types 'hello' into first box the 开发者_如何学Gosecond box will automatically fill with the same text. should happen as user types and not when user leaves text box

Thanks in advance


function SyncTextBoxes(txt)
{
    var t = $(txt).val();
    $('#<%= txtFirst.ClientID %>').val(t);
    $('#<%= txtSecond.ClientID %>').val(t);
}

and

<asp:Textbox ID="txtFirst" onkeypress="SyncTextBoxes(this)" runat="server" />
<asp:Textbox ID="txtSecond" onkeypress="SyncTextBoxes(this)" runat="server" />


Slight improvement to jelbourn's answer; best to use the onkeyup event otherwise the text will not include the last key pressed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜