开发者

Dynamically updating label text on textbox changes?

I want to display the text entered in a textbox on a label character 开发者_StackOverflowby 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?


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

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


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;
}


could also use a single line of jQuery

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜