I am working on this test page: http://www.problemio.com/index_new.php and you see the categories that are listed. They have associated sub-categories.
So what I want to have happen is if a person mouses-over on “Health” I want to present them with a list like:
- Personal Health
- Healthcare
- Diet
- Exercise
and there is a different sub-list for each category.
So my question is – since mouseOver looks like this: onmouseover="SomeJavaScriptCode"
I will likely have to call a JavaScript function, correct? If so, how do I populate the JS with the data from my PHP query? Should I create the JS during from my PHP since the data is dynamic? What approach is the best here?
Thanks!!
The approach that is commonly used is to get the data in php, call json_encode to make the object in javascript then have separate scripts which will handle the user interaction keeping the data separate from the behavior. In javascript to get the object make the call shown here and then you can do whatever you want in javascript.
you can do this in php
and then the data is in javascript for other scripts do display as they like.