Click here to Skip to main content
12,250,675 members (43,808 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET jQuery
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

$(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 23-Dec-12 19:29pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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:

$(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 Smile | :)
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.

<script type="text/javascript" src="Your js file name"></script>
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100