Showing posts with label updating. Show all posts
Showing posts with label updating. Show all posts

Monday, March 26, 2012

AJAX Automatic label updating while typing text

Hi,

I'm testing AJAX out and I have a question. Is it possible to display the tex that I write in a textbox onto a label without pressing a button? So when I type a "1" in the textbox, I want to see the "1" directly on the label aswell.

Thanks,
Jeff

Use javascript. Add an onchange function to your textbox.

<input type="text" onchange="WriteMe(this);" />
<asp:Label ID="lblMesgArea" Text="" runat="server" />

JavaScript Function:

function WriteMe(Mesg)
{
var mesgArea = document.getElementById('" & Me.lblMesgArea.ClientID & "');
mesgArea.value = mesgArea.value + Mesg.value;
}

There are other ways to do it too. This the first thing that comes to my mind =)

WS