0

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 second box will automatically fill with the same text. should happen as user types and not when user leaves text box

Thanks in advance

2 Answers 2

1
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" />
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

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.