John McKean Posted October 15, 2005 Share Posted October 15, 2005 Newbie - please forgive my ignorance.I have an upload form and I want to put a default value in the filename input.Since file inputs have no associated value="xx" method, I tried the following JavaScript using the DOM defaultValue property. I added a text input (test1) to verify that the script is executed. IE-6 correctly puts "abc" in the test1 box, but doesn't modify the file box or pass the defaultValue ("c:\test1.txt") to my PHP CGI file.Mozilla 1.7.8 doesn't appear to do anything at all.Is there something wrong with my approach or another method that would work?Thanks,John <html><head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <meta http-equiv="PRAGMA" content="NO-CACHE"><title>Upload</title><script type="text/javascript">function setDefaults(){document.getElementById("test1").value="abc"document.getElementById("userfile").defaultValue="c:\test1.txt"}</script></head><body onload="setDefaults()"><form enctype="multipart/form-data" action="test_upload.php" method="post"><input type="hidden" name="MAX_FILE_SIZE" value="1000000"><input name="test1" type="text">File to send: <input name="userfile" type="file" size="50"><br><br><input type="submit" value="Send File"></form></body></html> Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted July 19, 2008 Share Posted July 19, 2008 Instead of using the name attribute, use the id attribute like this: <input name="userfile" id="userfile" type="file" size="50"> As far as I know, IE incorrectly selects the element even with the name attribute when using document.getElementById. Link to comment Share on other sites More sharing options...
jeffman Posted July 19, 2008 Share Posted July 19, 2008 I would be very surprised if a modern browser let you set a default path for a file element. Since the file structure of every common OS is well-known, this ability would let web authors troll for files on the hard drive of any user that came along, stealing your passwords, etc. Very bad security. Link to comment Share on other sites More sharing options...
Synook Posted July 20, 2008 Share Posted July 20, 2008 FirefoxRocks, please stop digging up two-and-a-half years old topics Link to comment Share on other sites More sharing options...
jeffman Posted July 20, 2008 Share Posted July 20, 2008 CR@P! Another one?FireFox, what are you up to? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now