I have an index.php and a contact.php.
index.php uses load() like so: $("#content").load("contact.php"); and everything is great…
My problem is that on contact.php, there is a form, and I can’t seem to get functions to run when the form is submitted.
index.php has jquery loaded. I’ve tried putting this function in and out of a ready tag:
function contact_submit(){
alert('a');
}
on contact.php:
<form .....
<input onclick="contact_submit();" ....
I’ve been experimenting, and put the function on contact.php, but still no luck. I did notice that if I want to use jquery on contact.php I need to include jquery.js on that page (it doesn’t steal it from index).
Does anyone know what i’m doing wrong, or how I can have a function on index.php be used in the loaded contact.php? If you need more of my code please let me know…
EDIT Will I need to put my global function in a .js file and load them on all pages that will be used? I know it sounds like a basic question, but does using load() not re-use Javascript functions on my index page?
What you need to do is to add an event listener and execute the code after all the DOM Elements have been loaded, provided there are no bugs in your php.
A few of these may be:
The first two apply to individual pages, and the third to DOM.