Reputation: 67
I have a function that creates a form in javascript and submits it. It works as expected in Safari, Chrome, FF, & Opera but not IE 10.
When the from submits the browser is not pointed to the url in the action attribute in IE. I'm sure this is lame but I can't find the problem so any help would be greatly appreciated.
function checkout() {
var myDoc = 'some xml data to send'
var form = document.createElement("form");
form.setAttribute( "method", "POST" );
form.setAttribute( "action", "http://domain.com/script.php" );
var hiddenField = document.createElement("input");
hiddenField.setAttribute( "type", "hidden" );
hiddenField.setAttribute( "name", "myField" );
hiddenField.setAttribute( "value", myDoc );
form.appendChild(hiddenField);
form.submit();
}
Thanks for any help!!!
Upvotes: 1
Views: 114
Reputation:
You're creating the form, but you're not appending it to the document.
Add
document.documentElement.appendChild(form);
just before
form.submit();
Upvotes: 0
Reputation: 382092
On Internet Explorer you have to append the form to the document (I don't know if it's a bug or a feature).
Simply do
form.style.display = 'none'; // useful if you're targeting another window
document.body.appendChild(form);
Upvotes: 3