It did work.  I tried it before submitting the suggestion.  The jQuery submit() function works in 2 ways.  If a function is passed it will set that function to the onsubmit handler, and if no arguments are passed, it will call the submit action on the elements.  Your way will work as well due to the form element's built in submit function.  But I believe that my way will not throw an error if the form element is not found because jQuery functions fail silently on and empty set, whereas using the [0] to get the dom element first will throw an error if it doesn't exist.

Please let me know if I'm wrong though.  I could very well be.  Though, as I said, I did test my code before offering the suggestion.

On 10/18/06, Klaus Hartl <[EMAIL PROTECTED]> wrote:

> $("form#photo-upload-form")
>     .submit(function() {alert("inside");})
>     .submit();

That won't work. You have to get out the DOM node out of the jQuery
object first before calling submit() on it:

$("#photo-upload-form")
     .submit(function() {alert("inside");})
     [0].submit();
     ^^^

You have to be always careful with such code. Once the element
#photo-upload-form is not found for whatever reason an error will be
thrown, because yor are calling a function on undefined.

Speaking of optimizing queries, leave away the element type "form" in
front of your id selector as well.


-- Klaus

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to