Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to put a value in an input file box? 1

Status
Not open for further replies.

odenc

Programmer
Sep 16, 2005
9
IE
I am trying to put a value into an input file box. On the HTML form the user has the option to upload another file. If they have previously browsed and chosen a file, when the page refreshes this value is wiped. Because this would be a pain for users, I am trying to get it so the value is rewritten in the box on refresh, but am having issues trying to find a way to do it.
Should just putting something in the value field work?
<input type=file name=uploadfile value="Some value">
By adding the value field I am getting no change whatsoever.
Thanks,
Caroline
 
I am trying to put a value into an input file box.
You can't. It's not able to be set. This could constitute a security issue and would be open to abuse if it were possible. Treat the object as read-only (in terms of accessing it programitically or by setting it's value parameter).

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
you could use cookies or sessions to store the value temporarily
 
While there are Javascript hacks to do this, I'd take Jeff's advice - treat the field as if it were read-only.

when the page refreshes this value is wiped.

When the page is refreshed (by the user using a refresh button), I would expect things like this to be wiped. If the refresh you are talking about is the page reloading after a form submission, then you no longer need the file input box, and could make do with text-only.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
browsers are suppposed to ignore the file input field (for security reasons as mentioned) but it might be possible to populate the field using javascript and some trickery using hidden form fields or hidden frames. But really, it's not a good idea. Best advice: fugidaboudit :)
 
Thanks for the advice everybody! I think I am now going to have to focus on "user acceptance" to bypass this problem!
 
since they have to accept it on all other websites it's not going to take much effort on your part to enforce the rule.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top