Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text change events in jquery with Asp.net

I have 2 textboxes and If I write anythng in textbox1 it should reflect immediately in textbox2 and If I write anything in textbox2 it should reflect in textbox1.

So how do I do that? I have seen this article before and how to Implement between two textboxes?

http://www.zurb.com/playground/jquery-text-change-custom-event

Here are my textboxes:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
like image 897
coder Avatar asked Feb 22 '23 13:02

coder


2 Answers

$('#TextBox1').keydown(function(){
    $('#TextBox2').val($(this).val())
})
$('#TextBox2').keydown(function(){
    $('#TextBox1').val($(this).val())
})
like image 188
Sedat Başar Avatar answered Mar 06 '23 09:03

Sedat Başar


var $tbs = $("input[id^='TextBox']");
$tbs.keyup(function() {
    var that = this;
    $tbs.each(function() {
       $(this).val(that.value);
    }); 
});

Demo: http://jsfiddle.net/SGcEe/2/

like image 45
karim79 Avatar answered Mar 06 '23 09:03

karim79