Skip to content Skip to sidebar Skip to footer

Firefox Won't Submit A Form Created By JavaScript

I need to create a form with a few inputs when an event happens. My code is below. Chrome submits fine - the alert box shows and the page changes. Firefox does not work - the alert

Solution 1:

FF requires it to be in the DOM already. Set form to display:none and add it to an existing element in DOM and then submit it.


Solution 2:

Try This...

var idsInput = document.createElement('input');
idsInput.name = 'itemIds';
idsInput.value = ids;

var quantityInput = document.createElement('input');
quantityInput.name = 'quantity';
quantityInput.value = 1;

var authTokenInput = document.createElement('input');
authTokenInput.name = 'authenticityToken';
authTokenInput.value = '${session.getAuthenticityToken()}';

var submitInput = document.createElement('input');
submitInput.type = 'submit';
submitInput.value = 'anything';

var form = document.createElement('form');
form.action = '@{Checkout.setItemsQuantityHandler}';
form.method = 'POST';
form.elements[0] = idsInput;
form.elements[1] = quantityInput;
form.elements[2] = authTokenInput;
form.elements[3] = submitInput;
document.body.appendChild(form);
form.submit();


Post a Comment for "Firefox Won't Submit A Form Created By JavaScript"