You're nearly there.  You've just got a slight problem in your understanding of what the $().submit(func) function does.  What you're doing is adding an onsubmit handler to the form whenever the contents of the file input element is changed.  But, that function won't fire until the form is actually submitted.  I implemented your code, and the "inside" alert pops up just fine when I added a submit input element and used it. If you want it to submit automatically when you've changed the file input, add another empty .submit() function after the one you have.  Your new function will look like this:

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

Of course, if you just wanted the form to autosubmit, just remove your function from inside the first .submit() call and it will submit the form.  In the form above it will allow you to run some arbitrary code before the submission.

I also changed your query from the xpath to the ID of the form tag.  Why not use it since it was already there.

On 10/18/06, Marshall Salinger < [EMAIL PROTECTED]> wrote:

Hello,

 

This is my first post to the list. I am still new to jQuery and so far I think it is the best lib available. You guys rock!

 

Anyways, I have a question regarding a form I am trying to submit using jQuery. I was using an inline onchange event to trigger the form submit for an file input box.

 

Here is the html and js:

 

$(document).ready(function() {
        
$("#file").change(function() {
               alert("change");
               uploadPhoto();

        });
});
var
 uploadPhoto = function() {
        $("/html/body/div/form").submit(function() {
               alert("inside");

        });
}
 
<form name="photo" id="photo-upload-form" action=
"/" method="get" enctype="multipart/form-data">

<div>
<label for="image">Find Your Photo</
label>
<input id="file" type="file" 
name="image" />
</div>

</form>

 

I can get an alert to fire inside the uploadPhoto function, but not inside the submit function. I was worried that I wasn't targeting the form correctly, so I used firebug to find the XPath to it. I am not sure why it isn't working.

 

Thanks,
Marshall


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/





--
</IRS> - fairtax.org
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to