Question

i want my textbox to fire a textChanged client side (JS) event when a text is changed inside it.

i read many posts about it. most of them are talking about a code-behind event and the ones that talk about the client side tells to add attribute of onchange:

<asp:TextBox runat="server" ID="TextBox1" onchange="javascript: ontextchanged();"></asp:TextBox>

but this event only fires when i lose the focus on the textbox.

what is the solution to this ? how can i fire a JS function each time a text is changed inside the textbox?

Was it helpful?

Solution

Use onkeyup or onkeydown instead.

This will then run the function when you type or click on the textbox. You can also then detect the keycode of the event, and prevent the function if you dont want it to run for certain keys.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top