1

I have a textbox and 2 label

I would like to make that, whenever I change the value of the textbox:

label2 = textbox * label1

I tried using textbox_TextChanged but it requires me to click anywhere outside the textbox first.

Is there any way to make that the label2 will immediately change considering the value of the textbox regardless if there is any click or not?

Kerzoz
  • 331
  • 5
  • 18
  • try onkeypress event – lordkain May 12 '17 at 09:13
  • If you are free to use jquery, use the on blur or keydown for textbox to change the label text – Vinay Pratap Singh Bhadauria May 12 '17 at 09:16
  • look at this example......... [http://stackoverflow.com/a/21620452/2779561](http://stackoverflow.com/a/21620452/2779561) – Saveen May 12 '17 at 09:17
  • I think you need a javascript function. Get a look here http://stackoverflow.com/questions/16846091/update-textbox-when-changed-without-refreshing –  May 12 '17 at 09:19
  • I have never used jquery nor known how to enable it in my ms visual studio. If it doesn't bother you much can you link me to an article I could really enable it? Not many articles are giving much info about it. @saveen – Kerzoz May 12 '17 at 09:28

1 Answers1

3

The above answers mentioned in the comments can work, but you can also add a listener to TextBox1.

<asp:Label ID="Label1" runat="server" Text="10"></asp:Label>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<script type="text/javascript">
    $('#<%= TextBox1.ClientID %>').keyup(function () {
        var sum = parseInt($(this).val()) * parseInt($('#<%= Label1.ClientID %>').html());
        $('#<%= Label2.ClientID %>').html(sum);
    });
</script>
VDWWD
  • 35,079
  • 22
  • 62
  • 79