Re: Upload, input type=file, submit button

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Larry Brown said the following on 5/15/2006 3:55 AM:
Hi,

I still have the same problem with the input type=file element, its browse button, and the submit of the form.

No, these are new issues.

I want to hide the grey old-fashioned Browse button of the input type=file with another button.

There is a reason why you are having so much trouble trying to hide the input type="file" default look. It is a security issue. If you could programatically click it, fill it out, and submit the form then you have a very huge security hole.

As for styling it, you can't.
<URL: http://www.cs.tut.fi/~jkorpela/forms/file.html#present>

When I click on this button, it simulates a click on the Browse button. This works fine.

Only in IE.

Then:
- if I use a submit button, I have to click twice on it: the first time it simply clears the input field, and the second time the form is really posted, but the result is empty (no file).

Welcome to the security issue.

- if I use a form.submit() function (which I would prefer because I have things to control before I submit the form), I get an "Access denied" error from my IE.

Don't use form.submit(), use the onsubmit handler of the form:

<form onsubmit="return checkForm()">

Then you do your things in the checkForm function and return true or false to submit the form or cancel the submission.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
.


Quantcast