.submit() not working in IE

Im trying to submit a form in IE, but the submit doesnt fire in IE. I have tried Chrome and Firefox which works fine.

My code is kinda simple:-
		$(document).on("click","#btnRemoveSelectedImages",function () {
			var r = confirm("Are you sure you wish to remove the selected images?");
			if (r == true) {
				
				var newForm = $('<form>', {                
					'action': 'backend.php',
					'target': '_self',
					'method':'post',
					'id':'tmpForm'
					});
					
				newForm.append($('<input>', {
						'name': 'frmName',
						'value': 'RemoveImages',
						'type': 'hidden'
					}));		
					
				var noImgs = 0;
				$(".claImageSelected").each(function( index ) {
					noImgs++;
					newForm.append($('<input>', {
						'name': 'imgName_' + noImgs,
						'value': $(this).data("imgFilename".toLowerCase()),
						'type': 'hidden'
						}));
					
				});
				
				newForm.append($('<input>', {
					'value': "Submit",
					'type': "submit"
				}));	
				
				newForm.append($('<input>', {
					'name': 'NoImages',
					'value': noImgs,
					'type': 'hidden'
				}));

				newForm.submit();
			}
		});

Open in new window


It seems to generate the HTML fine, and I can see it if I call:-
alert(newForm.html());

Open in new window

However it seems to be missing the <Form> header and footer tags, which Im unsure why this is.

Ive read a few articles which suggest adding the form to the body then submitting it, which I have tried by:-
$("#hiddenForm").html(newForm.html());
$("#tmpForm").submit();

Open in new window

But again get the same error.

Any suggestions?
tonelm54Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
could you simply try and replace (in your above posted code)
newForm.submit();

Open in new window

with
newForm.appendTo(document.body).submit();

Open in new window

That should work.
I also added on top a call to prevent the default event handler
$(document).on("click","#btnRemoveSelectedImages",function (e) {
  e.preventDefault();
  ...

Open in new window


HTH
Rainer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
Rainer's solution is correct - you are creating the form but unless you actually add it to the document it does not exist in the DOM and therefore submitting it will have no effect.

This sample uses your code with a document append and posts to a script that dumps the $_POST (http://www.marcorpsa.com/ee/t1169.html)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.