How to work with OnChange Submit & Form Target to

2019-07-25 06:08发布

问题:

I'm having a slight problem.

I have set my <input type="file"> to onChange="this.form.submit()".

The file selector will fire the submit, but if I have my <form> element targeted to an iFrame, the browser will return a Popup blocked error and will stop the submit!

The .submit() works fine without a target specified - but as soon as I have a target, it'll block it!

Is there a work around for this?

Thanks.

EDIT: Here is the HTML:

<iframe src="about:blank" title="uploader_iframe" id="uploader_iframe" style="display:block;"></iframe>
<form target="uploader_iframe" action="upload.php" id="the_form" onsubmit="return validate()" method="post" enctype="multipart/form-data"><input type="file" id="beta_uploader" size="1" onchange="document.forms['the_form'].submit()" name="file" /></form>

Also, the validate() function does not get called :S

回答1:

Found the problem.

Forgot to Specifiy the iFrame with the tag <iframe NAME="uploader_iframe">