I need to have a MySQL table result in JS array so that i can search through the names when typed in a text box. I mean, lets say i have a table with some names, now when the page is requested, it should populate a div with the list of the names from MYSQL, the div needs to have an input box in which when initials are typed, the list below should find the names matching the keywords kind of like search.
For this, i think i need to store the mysql result in a JS array so that on the onkeyup
and onkeypress
event of the text box, it should search for the matching results from the array items and populate the list with only those items.
I know, i'll have to make an ajax request on document.ready
to fetch the results from database but then have no idea, how to store it in an array and then search through that on the text box events.
JSON.parse
and you are done. Have a look at the code in this question or googlephp javascript ajax json example
. If you don't know how to query the database, you have to learn that as well of course. – Felix Kling Aug 24 '13 at 7:03