views:

1064

answers:

3

Hi everyone,

I have a piece of javascript which is supposed to latch onto a form which gets introduced via XHR. It looks something like:

$(document).ready(function() {

   $('#myform').live('submit', function() {
      $(foo).appendTo('#myform');
      $(this).ajaxSubmit(function() {
        alert("HelloWorld");
    });
       return false;
   });

});

This happens to work in FF3, but not in IE7. Any idea what the problem is?

+1  A: 

How are you excuting the submit? Can you try this instead?

$(':submit').live('click', function(e) {
  $(foo).appendTo('#myform');

  $('#myform').ajaxSubmit(function() {
    alert('Hello World');
  });

  e.preventDefault();
  return false;
});
bendewey
That seems to do the trick ben, however the form is never posting to the server. I wonder if that's related to ajaxSubmit though?
I updated my code try that
bendewey
Hmm, it doesn't let the ajaxSubmit line, very odd. IE7 doesn't at least...
did you try both versions, $('#myform') and $('#myform').get(0)?
bendewey
.ajaxSubmit() is a jQuery function. It won't work on $('#myform').get(0).
Crescent Fresh
@crescentfresh, thanks I hadn't heard of ajaxSubmit. Edited.
bendewey
This will not let you submit the form via the Enter key
apphacker
+5  A: 

The submit event is not currently supported by Events/live.

Possible event values: click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup

Currently not supported: blur, focus, mouseenter, mouseleave, change, submit

CMS
A: 

Re CMS above, in JQuery 1.4, live is supposed to work with 'submit', but seems to still not with IE7. I'm going to try delegate instead and see if that helps.