| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||||||||||
|
|||||||||||
|
Classic ASP/AJAX - Auto Suggest Form
Hi Guys
I just posted this as a reply to this query , and thought I would share it here also OK, here we go: This is the main page, with a small form, and includes the javascript (further down this post) that talks to the ASP script on the server (even further down this post) to get the suggestions ASP Code:
This is the javascript: JavaScript Code:
and this is the ASP script on the server: ASP Code:
This one talks to the access database to get any words that start with whatever is the form field - and this is done each time the content of that field change (each and every keystroke) I have attached a ZIP file of this code with an Access DB, containing a list of Railway Station names in Sydney, Australia (300+ entries, so a good sample of the code can be run ).If you would like to see this in action, you can view it on my development server at http://dev.unimaetrix.com/hint/clienthint.asp The layout of the page is very simple as it is ony a sample of the scripts in action. Let me know if you need any further assistance , or if you find any errors in my code. ![]()
__________________
Alex - Lucky Number 13 Did I do something that helped you? - please click the scales and help my rep
|
|
#2
|
|||||||||||
|
|||||||||||
|
In the thread mentioned in the above post, there was a query about making the suggestions clickable, so here is some more code for that purpose:
Clickable suggestion that populate the text box I haven't got the autosubmit to work yet tho ASP Code:
JavaScript Code:
ASP Code:
New Zip attached of this version You can also see it working at : http://dev.unimaetrix.com/hint2/clienthint.asp I'll continue to try to get the autosubmit when a suggestion is clicked - if I succeed, I'll post the function for that here also |
|
#3
|
|||
|
|||
|
autosuggest
Do have a modified version of this code that would keep the suggested words in the textbox (from the databse field) so you can tab through or click on and then submit to your page.
Thanks! |
|
#4
|
||||
|
||||
|
Rather than using onkeyup straight, I'd recommend using something like the following function, which dramatically reduces the number of AJAX calls, and is still as (if not more) effective for the client.
Usage: Code:
<input type="text" name="q" onkeyup="search_delay(this)" /> Code:
function search_delay(element) {
// Create a function to get the search results
var func = function() { getBox(document.getElementById('ab_q').value, 'RhapArtist', 10); };
// Check to see if there is already a timeout and if so...
// ...cancel it and create a new one
if ( element.zid ) {
clearTimeout(element.zid);
}
element.zid = setTimeout(func,500);
}
__________________
www.simplelyrics.net - www.playstormgames.com.com - www.g1games.com - www.quotemeanings.net - www.ourfreegames.com |
|
#5
|
|||
|
|||
|
I am not able to get it to work. Am I suppose to but the following code in the bottom of the clienthint.js file?
Code:
function search_delay(element) {
// Create a function to get the search results
var func = function() { getBox(document.getElementById('ab_q').value, 'RhapArtist', 10); };
// Check to see if there is already a timeout and if so...
// ...cancel it and create a new one
if ( element.zid ) {
clearTimeout(element.zid);
}
element.zid = setTimeout(func,500);
}
Last edited by phoenixaz : July 4th, 2008 at 02:33 AM. |
|
#6
|
|||
|
|||
|
I think I am having a brain cramp because I can't seem to substitute my sql connection with your access database connection.
Here is my sql connection. Can you suggest how I make the changes? Code:
set objConn = server.CreateObject("adodb.connection")
objConn.Open application("my_ConnectionString")
SQL = "select * from table1 WHERE (studentname LIKE'" + q + "%') order by studentname"
Set objRS = objConn.Execute(SQL)
I tried changing objrs to rswords, but that didn't work. And when you had rsWords("word") I changed that to rsWords("studentname") Any suggestions would be appreciated. Thanks |
|
#7
|
|||
|
|||
|
I was able to get it to work, but had to comment out 5 lines of code. Any thoughts?
Code:
set objConn = server.CreateObject("adodb.connection")
objConn.Open application("My_ConnectionString")
strSQL = "SELECT studentname FROM table1 WHERE (studentname LIKE'" + q + "%') ORDER BY studentname"
Set rsWords = objConn.Execute(strSQL)
'rsWords.CursorType = 2
'rsWords.CursorLocation = 2
'rsWords.LockType = 3
'rsWords.Open()
'rsWords_numRows = 0
|
|
#8
|
|||
|
|||
|
You did a great job on coding gethint2.zip files.
If I want to add another field and pass it to the form, how can I capture the StudentID in the form? Code:
If trim(hint) = "" Then
hint = "<a href=""javascript:setTextBox('" & rsWords("studentname") & " (" & rswords ("studentid")& ")" & "','" & b & "','" & f & "','" & a & "');"">" & rsWords("studentname") & " (" & rswords ("studentid")& ")" & "</a>"
Else
hint = hint & " , <a href=""javascript:setTextBox('" & rsWords("studentname") & " (" & rswords ("studentid")& ")" & "','" & b & "','" & f & "','" & a & "');"">" & rsWords("studentname") & " (" & rswords ("studentid")& ")" & "</a>"
End If
That code works fine and the results would be something like this.... John Doe (1411) , John Doe (3288) , John Doe (3432) So I have 3 different students with the same name. So when I click on the one I want, it puts .... John Doe (3288) in the text box. So if I now click on SUBMIT, I want to put in the form the studentname and ALSO the studentid so I can use that in my sql string. Code:
<form name="form1" action="clienthint.asp" method="post"> Student Name: <input type="text" name="studentname" id="txt1" onKeyUp="showHint(this.value,'txt1','form1',true)"> <input type="submit" name="submit" value="submit"> </form> <p><span id="txtHint"></span></p> I appreciate your suggestions. Thanks! |
|
#9
|
||||
|
||||
|
Quote:
|
|
#10
|
|||
|
|||
|
Last name search
Is it possible to do a search with your autosuggestion for the last name when the name field contains both first, last and sometimes middle.
Example: Let's say that there are 2 names, John Doe Smitih , John Smith If you type.... John, both names show up in the suggest list. If you type.... John D, then only John Doe Smith shows and not John Smith. I think there is a way to do a split, but I am not sure how to do it. Thanks Last edited by phoenixaz : July 7th, 2008 at 07:55 PM. |
|
#11
|
|||
|
|||
|
any progress on autosubmit?
Dear alexk13,
thanx for the nice piece of code. do you have any progress on autosubmit? would be great if you did. |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Classic ASP/AJAX - Auto Suggest Form |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|