I thought I’d see if I could find some “point me in the right direction” help here for a JavaScript problem I’m having. I’ve been programming for 20+ years, but I’ve never focused on JavaScript, I’ve only recently started using it more often.
I’ve got a PHP page that has a form on it. A button on the form calls a JavaScript function, which goes through some gyrations and “calls” a different PHP script, which puts together a string, which the JavaScript function then stuffs into a div tag on the original page (which is also inside the form) via the innerHTML. This was all written by someone else, and while I don’t understand every single thing that’s happening, I get the overall flow.
I’ve been tasked with adding some form elements (checkboxes, and potentially some selects) to the string that’s returned by the PHP script. The idea is that checking any of the checkboxes should trigger the same JavaScript function as the button, so that the string that’s returned (including the new form elements) is re-updated.
Getting the new form elements into the string was no problem. My problem is that the JavaScript function doesn’t seem to recognize them after they’ve been added to the form. I know that sometimes JavaScript can be included early on (e.g., in the head tag), and sometimes it has to be written in-stream; I’m wondering if the problem here is that the function recognizes the initial form elements but doesn’t recognize the elements that are added later for no other reason than that they weren’t there originally.
So if that’s the case, can anyone suggest an approach to be able to use the new form elements to call the same updating function? And if that’s not the case, what am I missing when it comes to the function recognizing the new form elements?
Thanks for any insight.
Cheers,
Rich