Marios Fakiolas
Marios Fakiolas

Reputation: 1545

Fancybox v2.1.3 ajax load form

Hi again to all fancybox lovers. I got stuck with ajax load an external html form into current viewed html file. I use a hidden trigger with class="fancybox.ajax" in a tag that is brought into html that way:

$('body').prepend('<a class="fancybox fancybox.ajax" href="form.html" style="display: none;"></a>');

so that form can be brought next with following into html:

$(".fancybox.ajax").trigger('click'); 

But this fails. Maybe i need "on" or "live". I do not know if there is a better way to achieve this. Then i want to make some js checks over form submission but how this will run? Maybe some good use of "on"

 $('#submit').on(click, function({ .... }));  

Any help will be much appreciated.

Upvotes: 0

Views: 635

Answers (2)

Marios Fakiolas
Marios Fakiolas

Reputation: 1545

Ok the answer to submit the form that is brought with ajax is only

$("#submit").live('click', function() { ... });

till now, i could not make on() to work by no means.

Upvotes: 0

JFK
JFK

Reputation: 41143

Rather try

$(".fancybox").trigger('click'); 

... the class fancybox is used to bind such selector to fancybox while the fancybox.ajax class is used to define the type of content (you don't need to use live since fancybox v2.x already uses that method)

On the other hand, if you want to perform some actions on form submit, try binding the .on() method to the form selector (not the submit button) like

$('#formSelector').on("submit", function({ //do somthing })); 

Upvotes: 1

Related Questions