Hi all this is probably really simple to fix and maybe down to my misunderstanding of jQuery.
Im building a document centre and when users click on different buttons it loads form into the page using load(), this form is then displayed centre of screen with CSS. Once completed the form submits by ajax closing the form.
i have functions wrapped in a $(function(){}); to listen for button clicks and load the relevant for but when a form is loaded the on submit listener doisnt pick up the form. I'm assuming because the form wasn't included when the DOM was generated this is why it cannot be read by my scripts
function window_form(form="") {
$('#popup_bg').addClass('show').load('/ajax/'+form);
$('.closeWindow').live('click', function(e){
$('#popup_bg').removeClass('show');
$( "section" ).remove( ".windowCard" );
});
}
$(function(){
// Submission listener
$('form').on('submit', function(e) {
e.preventDefault();
ajax_submit($(this));
});
// check for window form button and load the form
$(".windowForm").click(function(e) {
e.preventDefault();
window_form($(this).data("form"));
});
});
So any forms on the page this all works great and if submitted sends to the ajax_submit(). So is there a way to initialise the forms once the load completes so they can be picked up buy the submit function. i was looking a .live but isnt this getting removed.
i could include my script in all the form files which works but that seem hacky and loading multiple jquery sessions.