capturetheflag
asked on
Autocomplete jQuery not working in Classic ASP page
Hello,
I am trying to get jQuery auto-complete to work in a classic ASP web page.
But is not working
Thanks for the help.
I am trying to get jQuery auto-complete to work in a classic ASP web page.
But is not working
Thanks for the help.
<%dim output, outstr%>
<%if not rs3.eof then
'output = ""
do while not rs3.eof%>
<%'response.write rs3("first_name") & " " & rs3("middle_name") & " " & " " & rs3("last_name") & " " & rs3("user_id") & "<BR>"
output = rs3("first_name")
outstr = """" & output & ""","
response.write outstr %>
<%rs3.movenext
loop
end if %>
<script type="text/javascript">
$(function() {
var availableTags = [<%= outstr%>];
$( "#username" ).autocomplete({
source: availableTags
});
});
</script>
The problem is your trying to mix server side code and client side code. Your asp/vb is serverside code and runs on the server BEFORE the html is written to the browser. Javascript and jquery are client side languages and run AFTER the html and css loads.
What you need to do is look at the sample code http://jqueryui.com/autocomplete/ and generate the html from your asp.
The link I gave you has this sample
What you would do in your asp code is this
What you need to do is look at the sample code http://jqueryui.com/autocomplete/ and generate the html from your asp.
The link I gave you has this sample
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
What you would do in your asp code is this
<%
dim theChoices
theChoices=""
do until rs3.eof
theChoices=theChoices&"""&rs3("first_name")&"""
rs3.movenext
if not rs3.eof then
theChoices=theChoices&"," ' only add a comma if more data
end if
loop
' You should now have a file looking like: "Bog","Dan","Pete", "Roger"
$(function() {
var availableTags = [
<%=theChoices%>
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
ASKER
Hello Padas,
Thanks for your help. Yes, I have looked at the jQuery site for auto complete.
I have it working now. Here is my code. Please let me know if the code could be cleaned up in any way. Thanks again.
Thanks for your help. Yes, I have looked at the jQuery site for auto complete.
I have it working now. Here is my code. Please let me know if the code could be cleaned up in any way. Thanks again.
<%
dim output, outstr, mystring%>
<%
if not rs3.eof then
do while not rs3.eof
theChoices=theChoices&""&rs3("first_name")&""","""
rs3.movenext
loop
end if
'''''cleanup and reformat string
theChoices = Replace(theChoices,""","""",""","")
theChoices = """"&theChoices &""""
'response.write theChoices
%>
<script type="text/javascript">
$(function() {
var availableTags = [<%=theChoices%>];
$( "#username" ).autocomplete({
source: availableTags
});
});
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help Padas. I am opening a new thread about auto complete and hitting a 100 thousand user name db.
Ok, please post the link to the question here.
In short, on the asp page that generates the 100K names, you want to make the query only trigger after x amount of characters have been typed. Typically I would wait until at least 3. Then in your query you probably want to limit the total to 50 or so.
Your sql might look like:
In short, on the asp page that generates the 100K names, you want to make the query only trigger after x amount of characters have been typed. Typically I would wait until at least 3. Then in your query you probably want to limit the total to 50 or so.
Your sql might look like:
theName=request("name")
"Select top 50 firstName+' '+lastName as FullName from mytable where firstName like '"&theName&"%'
can you please post the generated HTML of your page?
Thanks.
Rainer