I am trying to fire a function using Jquery when the form submit button is clicked, but the function needs to fire BEFORE the form is actually submitted.
I am trying to copy some div tag attributes into hidden text fields upon submission, and then submit the form.
I have managed to get this to work using the mouseover function (when the submit button is hovered over), but this will not work on mobile devices using touch.
$("#create-card-process.design #submit").on("mouseover", function () {
var textStyleCSS = $("#cover-text").attr('style');
var textbackgroundCSS = $("#cover-text-wrapper").attr('style');
$("#cover_text_css").val(textStyleCSS);
$("#cover_text_background_css").val(textbackgroundCSS);
});
I have played around with the submit function, but the values are not saved within the fields as the function fires when the form is submitted and not before.
Many thanks.
submitevent (on the form) should run when you click the submit button, and it will run before the form is submitted natively. You can also try using aclickevent on the submit button itself.submitfunction, I don't understand your last sentence. What does "values are not saved within the fields" mean? Do you have any other JavaScript (validation maybe) on the form?timeoutis also an option..val()function. The values should be there.