Javascript Event in Innerhtml Resulting from PHP Server Script

Posted by user144527 on Programmers See other posts from Programmers or by user144527
Published on 2014-05-27T05:30:30Z Indexed on 2014/05/27 9:54 UTC
Read the original article Hit count: 205

Filed under:
|

I'm (very slowly) making a website, and I'm creating a search engine for the database, which is essential to organize the dependencies during data entry.

Anyway, what I would like is to type a few keywords into a box, have a menu pop up with various search results, and have the box fill with the ID number of the selected entry when it's clicked.

Currently, I have a document called search.php which fills a div called search-output using xmlhttp.open() and the innerhtml property. Everything is working perfectly except for filling the original search box with the ID number when clicking.

My first attempt was to add an onclick event to each entry in the output from search.php. Unfortunately, I found that javascript inserted into innerhtml is not run for security reasons. I've been Googling for hours but haven't been able to find a solution.

How can I get the original search text box to fill with the correct ID when I click it? Is what I'm doing a good setup for the results I desire, or is there a better way to integrate search features into data entry?

© Programmers or respective owner

Related posts about web-development

Related posts about JavaScript