Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a jquery function for autocomplete which i'm calling in the .aspx page itself. I moved it to a .js file. And now its not working, I dont knw how to call.

here is the function

C#
$(document).ready(function () {
           $('#<%=txtCity.ClientID%>').autocomplete("Ashx/Handler.ashx",
               {
                   delay: 2,
                   minChars: 2,
                   matchSubset: 1,
                   matchContains: 1,
                   cacheLength: 15,
                   selectFirst: true,
                   autoFill: false
               }
           );
       });



<asp:TextBox ID="txtCity" class="tb" runat="server" onchange="reset_CityCode();">


if I moved this query to a seperate file then how to call the function in the aspx page


Regards
CHinnu
Posted

Hello,


Check this out. I hope this will help you


http://forums.asp.net/t/1384485.aspx[^]

You will have to pass reference of textbox to external js file's function
 
Share this answer
 
v2
Hi chinnu,

Check the id of your server control (TextBox) in final HTML output in browser using View Source (I assume you must be knowing how to check Source code of an HTML file in browser). Put the id directly into your javascript function:

JavaScript
$(document).ready(function () {
           $('#myTextbox').autocomplete("Ashx/Handler.ashx",
               {
                   delay: 2,
                   minChars: 2,
                   matchSubset: 1,
                   matchContains: 1,
                   cacheLength: 15,
                   selectFirst: true,
                   autoFill: false
               }
           );
       });


and if you move the javascript function to somewhere else, just refer the file in your aspx page and use Response.Write to call the javascript function. See my answer for this question here: Call JavaScript function on DropDownList SelectedIndexChanged Event[^]


Hope this helps.
Happy Coding :)
 
Share this answer
 
v2
Comments
chinnu11 24-Dec-12 3:21am    
Hi,

I already added the src attribute to HTML script tag and specify the location of the external JavaScript file.
What i want to know is when we type a letter on the textbox how it calls the external js file. I'm not calling any function in the js query also.

regards
Chinnu
You are calling the method on document.ready, instead call it on the text change event. Refer my tip hope it helps
Autosuggest using jQuery[^]
 
Share this answer
 
To link to an external JavaScript file, you add a src attribute to your HTML script tag and specify the location of the external JavaScript file.

JavaScript
<script type="text/javascript" src="Your js file name"></script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900