Reputation: 83
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
Reputation: 5427
could also use a single line of jQuery
$("id$=myTextBox").keypress(function() { $("id$=myLabel").html( this.value ); });
Upvotes: 0
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
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