By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,573 Members | 1,208 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,573 IT Pros & Developers. It's quick & easy.

Setting a FILE INPUT element

P: n/a
Hi,

How do I set a file input element? If it's a text input, I can set the
value property. But this doesn't work with file inputs.

And no, I can't change it - I'm writing a script to automate a process
on an existing system.

Jim Witte
js*****@bloomington.in.us
Indiana University CS
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Jim Witte wrote:
Hi,

How do I set a file input element? If it's a text input, I can set the
value property. But this doesn't work with file inputs.

And no, I can't change it - I'm writing a script to automate a process
on an existing system.

Jim Witte
js*****@bloomington.in.us
Indiana University CS


How do you mean, how can you set a file input element? Are you using
<input type="file"> and want to specifiy a default file/path?

If this is true, you shouldn't be able to - more because of a security
precaution... I asked a similar question sometime last year and the
response to my post was that most web browsers wouldn't permit such.

In addition, I have the O'Reilly Javascript Pocket Reference which, on
page 92 says "Note that for security reasons, the value property of
elements of type "file" is usually read-only."

Note the word is "usually" (their choice of words, not mine) - you might
find it possible with one or two browsers but it won't be reliable.

Does that help you any?

laters
randelld
Jul 23 '05 #2

P: n/a
Jim Witte wrote:
How do I set a file input element? If it's a text input, I can set the
value property. But this doesn't work with file inputs.

<snip>

http://www.blooberry.com/indexdot/ht...e.htm#peculiar

Input Type=File
Browser Peculiarities

* Internet Explorer and Netscape do not use the VALUE attribute as the
default contents of the input area. Any default value set via HTML is
not usable via scripting and the DOM as well (hence it is not listed as
'supported' in any of the browsers.) If a user enters text in the field
however, that value is then reachable via the DOM as it normally would
be for a normal INPUT field (via the .value property.) The reason for
this behavior would presumably be to ensure the security/safety of users
against malicious authors. Opera displays the default VALUE attribute
value and submits it as well (although it prompts for confirmation on
submit if you have not altered that value.)

* Netscape 2+ only supports the onChange event handler attribute in
cases where the user enters or modifies text via the text box; if the
"Browse..." button is the only thing used, the event is not fired.
Internet Explorer 4.0+ fires the event in both cases.

* Netscape 4+ allows some Character-level formatting to be applied to
the contents of this form field. These physical formatting elements
(along with virtual formatting elements that are rendered identically,
such as EM and I) apply to this form field: I, U, S, STRIKE, SUB, SUP,
BIG, SMALL, FONT SIZE and FONT FACE.

* Using a READONLY attribute in IE4 and IE5 on this element still allows
a user to invoke the file...open dialog (from the "Browse..." button),
although the text field is not directly editable. In IE5.5 plus, both
the text field AND the file...open dialog are not usable.

* Opera 5/6: Using the DISABLED attribute still sends the name/value
pair for the element to the form processing script. It should not do this.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.