views:

69

answers:

3

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?

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

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

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;
}
DavRob60
surely it would be `runat="client"` ?
FallingBullets
runat="client" does not exist, you have to use standard HTML to do this behavior. And it may need to get the controls's values form the server side on post-back (submit).
DavRob60
A: 

could also use a single line of jQuery

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