I have the following function that collects data from a page, stuffs them all into the 'data' variable, appends it to a form then submits it.
$(document).ready(function () {
$('#content-tab .submit').click(function () {
var data = {champion: window.selectedChampion, runes: runes, masteries: masteries, items: items, skillingOrders: skillingOrders, chapters: chapters, title: $('#guide_title').val()};
data = JSON.stringify(data);
$("<form method='post'>").append($('<input type="hidden" name="data" id="data">').val(data)).submit();
});
});
There is a div on the page that triggers this when clicked on:
<div class='button pointer submit'>Submit</div>
All is well when tested in Chrome. The form submits then redirects to a page, just as planned. But while testing in Firefox (v. 5 and 6), clicking on the div does nothing. Nada. Zilch. I wonder what went wrong in Firefox? Any help would be highly appreciated. Thank you.
The NUMBER ONE error is having ANYTHING with the reserved word submit as ID or NAME in your form. If you plan to call . submit() on the form AND the form has submit as id or name on any form element, then you need to rename that form element, since the form's submit method/handler is shadowed by the name/id attribute.
Forms can be submitted either by clicking an explicit <input type="submit"> , <input type="image"> , or <button type="submit"> , or by pressing Enter when certain form elements have focus.
jQuery submit() Method The submit event occurs when a form is submitted. This event can only be used on <form> elements. The submit() method triggers the submit event, or attaches a function to run when a submit event occurs.
I would try adding the form to the DOM before submitting.
$('#content-tab .submit').click(function() {
var data = {
champion: window.selectedChampion,
runes: runes,
masteries: masteries,
items: items,
skillingOrders: skillingOrders,
chapters: chapters,
title: $('#guide_title').val()
};
data = JSON.stringify(data);
var $form = $("<form method='post'>").append($('<input type="hidden" name="data" id="data">').val(data));
$form.appendTo("body").submit();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With