I would have thought this is fairly classic, but I haven't found an answer.
I have a form which links to a MySQL (actually MariaDB) database table, contacts.
Part of the jQuery.ready() function populates, by AJAX, a drop-down list (i.e. <select id="drop_box" />
for example) with options, which are all the surnames + first names in the contacts table, with value = ID field from the record. Just to clarify, the injected code contains <select>
as well as all the options.
Then when the user clicks on/selects one of these names I want the value (ID field) of the option to be sent to a JS/jQuery function, perhaps defined in the <head>
tags.
The idea would then be another AJAX call to fill various other boxes and tables and things on the page with all the other details plucked from the contacts table.
But how to get either
- an existing
$("#drop_box").change()
function to "see" and respond to events in the injected<select>
objet or - if injecting the
change()
functionality, how to get the latter to call an existing function on the page.
It strikes me as bad practice to inject all the response code as a return AJAX call, and anyway I'd just like to know how injected JS code can be made to interact with JS code already on the page.