30

I want to submit a with using jquery as below;

$("#formid").submit();

Its working perfect in all browsers except IE6.

How to make it work in IE6 ??

djmzfKnm
  • 26,679
  • 70
  • 166
  • 227

8 Answers8

64

You probably have an <input name="submit" /> somewhere in your form, which overwrites the function "submit" of the form in IE.

Edit:

I have tested in some other browsers. The latest versions of all major browsers seem to be affected by this issue.

  • IE - all versions
  • Firefox 4+
  • Chrome at least since version 12
  • Opera at least since version 11

Bottom line: Never name your inputs "submit", or any other default property or method of the form element (e.g. "action" or "reset") . See MDC for a complete overview.

I.devries
  • 8,747
  • 1
  • 27
  • 29
14

I had a similar problem when I was about to submit the form via an A-element. I had set the href attribute to "javascript:;" to let the main jQuery script handle the actual submit but it just wouldn't work in IE6.

jQuery main script:

$(".submitLink").click(function(){
$(this).parent()[0].submit();
$(this).addClass("loading");
});

My solution was to change the href attribute from "javascript:;" to "#".

  • 1
    Excellent, in my case I set the href to "javascript:void(0);". All events hooked into click() fired, but the form would not submit. Changing the href to "#" fixed it. Thanks! – Peter J Oct 22 '09 at 22:46
  • Same problem as Peter, fixed. Thanks a lot! – Marco Z May 25 '10 at 08:10
  • 1
    $(".submitLink").click(function(event){ event.preventDefault(); // prevent browser from scrolling to top of page }); – Chris Jacob Sep 15 '10 at 03:03
3

You could try $("#formid").trigger("submit"), though I doubt it'll give you a different result.

Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238
2

I've recently had a similar issue, where I was creating a "pseudo-form" within an ASP.NET server form (so I couldn't use another form tag), which I wanted to post to another domain without needing to write server-side code to do the remote post. Easy answer - create a form on the fly and submit it. Works in good browsers...

After some trials and tribulations, I realised that IE won't work as expected (what a surprise) unless the form that is being submitted has been added to DOM. So, this was my solution. I hope it helps some of you. Please be aware, all of my inputs and my submit were in the same container. ".post-to" is a hidden input with the URL.

$(".post-form").click(function(ev) {

    var postto = $(this).siblings(".post-to").val();    
    var form = document.createElement("form")
    $(form).attr("id", "reg-form").attr("name", "reg-form").attr("action", postto).attr("method", "post").attr("enctype", "multipart/form-data");

    $(this).siblings("input:text").each(function() {
        $(form).append($(this).clone());
    });

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

    return false;
});

Eventually, it works a treat.

Tommy W
  • 649
  • 6
  • 8
1

Don't forget to return false; if you're on an tag

0

Add a button in your form with type="submit"

Reference.

Leif Gruenwoldt
  • 13,561
  • 5
  • 60
  • 64
-1
...

$('.bt_ok').bind('click', function() {
    $('#form_autosuggest').submit();
    return false;
});

...

Add after: return false; for IE6

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
miguel
  • 1
-1

Just add a

window.setTimeout(function(){
    $("#formid").submit();
}, 300);
Topera
  • 12,223
  • 15
  • 67
  • 104