jQuery .ajax() not working in external form

Permalink
Is there some strange reason why none of my jQuery works on a click event for a submit button in an external form? Like:
$('#ss_button').click(function(e) {
//nothing in here works...
});

Other jQuery in the external form works fine, but nothing in the button's click event. If I do the same form as a single page with the same jQuery, the form does an ajax submit/load when the user clicks the button, just like I want it to. So what gives with the external form?

Benji
 
esand replied on at Permalink Best Answer Reply
Does the click event trigger? You mention in your code excerpt that nothing within the click event fires. If this is the case, and that javascript is being properly loaded on the page with your form then you'd have to post more info.

If however, the click event does trigger but your AJAX calls aren't working, you may want to check to ensure that you're not violating AJAX restrictions with regards to cross site scripting. I believe all browsers will not allow an AJAX call from one domain to another - something like that anyhow (it's documented somewhere on MDC for Firefox).
Benji replied on at Permalink Reply
Benji
Thank you for your response. I did manage to get it working, and it turned out to not be a problem with c5 at all (which I couldn't really imagine it would be in the first place, but I couldn't figure out what else was wrong).

The problem was that I had unwittingly placed my form on the page twice, and my jQuery selector was only selecting the first #ss_button, which I didn't realize was there, and not the second one I was looking at since it shared the same #ss_button ID. Silly me.
esand replied on at Permalink Reply
IDs are supposed to be unique :) You can use a class as many times as you like, but an ID should be used only once. JQuery uses this assumption to speed up its selection of tags with an ID attribute and will only ever use the first one it finds, which would be why you encountered your problem :)
Benji replied on at Permalink Reply
Benji
Yes, I realize that. There weren't supposed to be two forms on the page, only one. If there were only one, there would be only one of each ID. ;)