Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP textbox calls javascript function

I have a search textbox in asp. And I want it to send request to the server each time the text is changed there. I have a javascript function which sends request but it is not being called each time when I type something in the text box. How can I call javascript function from ASP textbox?

That is my textbox:

<asp:TextBox ID="search" name="Search" runat="server" onchange="javascript:text_changed();"></asp:TextBox>

That is my js function:

function text_changed() {
     searchedword = document.getElementById("ContentPlaceHolder1_search").value;
     SendRequest();
}
like image 416
FarizHuseynli Avatar asked Dec 26 '22 06:12

FarizHuseynli


1 Answers

You should use onKeyPress event to call the function.

<asp:TextBox ID="search" name="Search" runat="server" onKeyPress="javascript:text_changed();"></asp:TextBox>
like image 176
Shivam Gupta Avatar answered Dec 27 '22 20:12

Shivam Gupta