Ramakrishna
Ramakrishna

Reputation: 83

Dynamically updating label text on textbox changes?

I want to display the text entered in a textbox on a label character by character.

I.e, if I enter a character in textbox, I need to display that character in the label. Up to the length of the textbox, this procedure has to done for the label also.

How can i achieve this?

Upvotes: 1

Views: 5130

Answers (3)

Dave Thieben
Dave Thieben

Reputation: 5427

could also use a single line of jQuery

$("id$=myTextBox").keypress(function() { $("id$=myLabel").html( this.value ); });

Upvotes: 0

Brij
Brij

Reputation: 6122

<script language="javascript">
function Changed(textControl)
{
  document.getElementbyId('label').value = textControl.value ;
}
</script>

<asp:TextBox id="txtName" runat="server" onchange="javascript:Changed(this);" />

Upvotes: 3

DavRob60
DavRob60

Reputation: 3557

a javascript i better in that case. for a character by character basis, use onkeypress javascript event. will also work with the onchange event.

<asp:Textbox onkeypress="WriteName(this.id);" id="txtT" runat="server">
<asp:label id="Test" runat="server">

function WriteName(id)
{
document.getElementById('<% = Test.ClientID %>').value=document.getElementById('<% = txtT.ClientID %>').value;
}

Upvotes: 0

Related Questions