0

I have a bit of a problem submitting my forms in Internet Explorer. It works fine in other browsers like Google Chrome and Firefox.

Here is my code:

form action="?page=addStorageEngine" method="post" id="createStorage">
   <tr>
       <th>Storagename:</th>
       <td><input type="text" name="givenStorageName" value=""></td>
   </tr>
</form>

<input form="createStorage" type="submit" value="Opprett Lager" href="?page=storageAdm">

And here is my jquery code:

$(function POSTstorageInfo() {

$('#createStorage').submit(function () {
    var url = $(this).attr('action');
    var data = $(this).serialize();

    $.ajax({
        type: 'POST',
        url: url,
        data: data,
        dataType: 'json',
        success: function () {
            UpdateStorageTable();
        }
    });
     return false;
  });
});

It seems like it won't trigger "submit" function. But how to make this work in IE?

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
Uptotrix
  • 59
  • 1
  • 6
  • It might be as simple as ensuring your submit button is inside the `form` tag. But you could try this: change `type=submit` to `type=button` and `.submit` to `.click`. – freedomn-m Mar 29 '17 at 15:45
  • It does actually work when I move it inside the form tag! But is it possible to make it work, and still have it outside? – Uptotrix Mar 29 '17 at 15:53
  • isn't Explorer supposed to support HTML5? form attribute is a HTML5 element as far as i know? – Uptotrix Mar 29 '17 at 15:57
  • Imagine you have 3 `form` tags on your page, which form should it submit? Chrome will likely go "oh, there's only one, I'll assume you mean that one" while IE will go, "errr, you're not in a form, don't know what to do, so I'll do nothing". – freedomn-m Mar 29 '17 at 16:05
  • 1
    See here for more info: http://stackoverflow.com/questions/7020659/submit-form-using-a-button-outside-the-form-tag – freedomn-m Mar 29 '17 at 16:05
  • Possible duplicate of [Submit form using a button outside the
    tag](http://stackoverflow.com/questions/7020659/submit-form-using-a-button-outside-the-form-tag)
    – freedomn-m Mar 29 '17 at 16:06
  • 1
    I found a workaround in the link from freedomn-n, Thank u! – Uptotrix Mar 29 '17 at 16:25

1 Answers1

0

Change this:

$('#createStorage').submit(function () {

to this:

$(document.body).on('click', '#createStorage', function (e) { 

The submit action will not be valid outside of the form tag