Let’s say for sake of argument I have:
<select id="lvl1">
</select>
<div id="lvl2">
<select id="lvl2a">
<select id="lvl2b">
<input text id="lvl2c">
</div>
<select id="lvl3">
</select>
in file1.php and I would like to populate <select id="lvl3"> with the results of a query which would essentially look like:
SELECT * FROM lvl1 WHERE fld_a = lvl2a AND fld_b = lvl2b AND fld_c = lvl2c
The snag is lvl2 is created dynamically in an external js file (file2.js) based on what the user chooses in lvl1. From everything I have seen it would seem I want to use JSON for this but how would I call a PHP function located in file3.php from an external js file, file2.js and return those results as an array to populate lvl3 in file1.php?
Hopefully I have explained myself well enough. Thank you in advance.
You’re going to need to refactor how your markup is generated in order to get this to work. Here’s how I would do it:
lvl1is spit out from your PHP script when the page loads.lvl1, you fire off an AJAX request back to the server with what they chose.lvl2which you inject into the page.lvl2to fetch the content oflvl3.That should be enough to get you going.