|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Autocomplete Text Field using Database Results
I have script that suggests autocomplete terms as a user is typing text into a field. Currently, the script uses a hard-coded array as I wanted to get the function working first. Towards the end of the script, I define and call the array:
function createAutoComplete(){ var aNames = [ "A MACEO WALKER MIDDLE SCHOOL", "ADAMSVILLE JUNIOR / SENIOR HIGH SCHOOL", "AIRWAYS MIDDLE", "ALCOA HIGH SCHOOL" ... ]; new AutoComplete( aNames, document.getElementById('theText'), document.getElementById('theDiv'), 25 ); } Additionally, I have a separate function that executes when the page loads to generate an array from a SQL query. The data is defined by in the array '$result' and contains the information: Array ( [0] => Array ( [name] => A MACEO WALKER MIDDLE SCHOOL ) [1] => Array ( [name] => ADAMSVILLE JUNIOR / SENIOR HIGH SCHOOL ) [2] => Array ( [name] => AIRWAYS MIDDLE ) [3] => Array ( [name] => ALCOA HIGH SCHOOL )) ... (The array actually has over 800 elements in the result.) Since the array contents will differ depending on a State ID, how do I pass the $result data into the javascript? Thanks. |
|
#2
|
|||
|
|||
|
This is actually a PHP question.
|
|
#3
|
|||
|
|||
|
This is just an example of building a JavaScript array from PHP:
PHP Code:
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|