I have the following inline code that I can’t change due is outputted by a foreigner plugin. Contain a onclick handler that trigger the submit event:
<input type='button' id='gform_next_button_12_188'
class='button gform_next_button' value='Next' tabindex='3'
onclick='jQuery("#gform_target_page_number_12").val("2"); jQuery("#gform_12").trigger("submit",[true]); '/>
I want to run some routines before submit the form and I tried this:
$("#gform_12").submit(function(e){
// this code is not running ...
});
That it is failing, ie, my code is not running when form is submitted . Any suggest?
Final solution based on answers given
var inline_onclick_code_on_next = $(".gform_next_button").first().attr("onclick");
$(".gform_next_button").removeAttr("onclick");
$(".gform_next_button").bind("click", function() {
myClass.autosave_on_click(inline_onclick_code_on_next);
});
myClass = {
errorMessage : "",
autosave_on_click: function (inline_onclick_code){
my_gravity_form_saving_running = 1;
myClass.saveData(); // this code must put my_gravity_form_saving_running = 0 when all data be saved
countdown_max_loop = 10; // seconds
var countdown = window.setInterval(function(){
if (countdown_max_loop-- == 0 || my_gravity_form_saving_running == 0){
clearInterval(countdown);
eval (inline_onclick_code);
}
}, 1000);
}
}
Try to unbind the click event from the element and then specify your own.
Edit:
added removeAttr, thanks @gdoron