Aaron
Aaron

Reputation: 2450

how do you make form.submit() work in firefox?

I've implemented the following code:

function post(path, params) {

    var form = document.createElement('form');
    form.setAttribute('target', '_blank');
    form.setAttribute('method', 'post');
    form.setAttribute('action', path);

    var hiddenField = document.createElement('input');
    hiddenField.setAttribute('name', 'JSON');
    hiddenField.setAttribute('type', 'submit');
    hiddenField.setAttribute('value', JSON.stringify(params));

    form.appendChild(hiddenField);

    form.submit();

}

It works wonderfully in chrome, safari, and IE but does nothing when using firefox.

any ideas what the problem could be?

Upvotes: 1

Views: 79

Answers (2)

Quentin
Quentin

Reputation: 943922

You need to put the form in the DOM of the page before Firefox will submit it.

document.body.appendChild(form);
form.submit();

… should do the trick.

Upvotes: 2

vborutenko
vborutenko

Reputation: 4443

Try add

document.body.appendChild(form)

beforesubmit

Upvotes: 4

Related Questions