tedd wrote:
At 3:21 PM +0100 6/11/06, Stut wrote:
The form is being submitted to the current URL which will stop any
javascript executing at the time. What you need to do is prevent
the form from being submitted, or control when it is submitted.
Instead of using the onclick attribute on the button you should be
using the onsubmit attribute in the form tag to control this.
Fairly good explanation of this here:
http://www.htmlcodetutorial.com/forms/_FORM_onSubmit.html
-Stut
-Stut:
Great suggestion, but I think an "upload file" a different critter.
http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_FILE.html
For example, I took my above code and changed it like so --
<form method="post" enctype="multipart/form-data"
onSubmit="javascript:sndReq()"> <input type="file" name="image"
value="30000"> <input type="hidden" name="stage" value="1"> <input
type="submit" value="submit"> </form>
-- and the result was the same. The file uploaded, but nothing
happened.
I also took the code you referenced, exactly "as-was" and I changed
the <FORM statement to --
<form method="post" enctype="multipart/form-data" onSubmit="return
TestDataCheck()">
-- and it didn't work the way one would expect either.
Apparently, the "built-in" upload-file thing has it's own way of
processing events. What do you think?
Maybe I'm not understanding what you're trying to do. I think you're
trying to show an animated GIF before starting the file upload. Is that
right? If it is, this is what you need to do...
The form, with onsubmit="return sndReq()". sndReq does the AJAX image
thing (although I don't know why you're using AJAX here, but it doesn't
matter). sndReq *must* return false!!
When the AJAX request completes the response presumably gets handled by
another JS function. That function does whatever it needs to with the
AJAX response, and then submits the form. I'm not sure if
programmatically submitting a form calls the onsubmit handler, you'll
have to check that. If it does just make sure sndReq does nothing on the
second call except return true - that will tell the form it's ok to do
the submit.
Another way you might want to consider for this is to use an iframe. Set
the target of the form to an iframe, that way the JS running in the main
page will not get stopped.
Hope that helps.
-Stut
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php