| | |
Redesign an input type="file"
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
When using this HTML code:
You get a rectangle where the location is stored, and a button labelled "Browse..".
I would like to redesign the "Browse.." button and I was told this would have to be done using mainly javascript and abit of css (I thought it would be the other way around only abit of javascript and alot of css - which im prefering).
So any ideas how to redesign the "Browse.." button?
Note: The file is a php file which contains various input type="submit", etc.
Thanks, Regards X
You get a rectangle where the location is stored, and a button labelled "Browse..".
I would like to redesign the "Browse.." button and I was told this would have to be done using mainly javascript and abit of css (I thought it would be the other way around only abit of javascript and alot of css - which im prefering).
So any ideas how to redesign the "Browse.." button?
Note: The file is a php file which contains various input type="submit", etc.
Thanks, Regards X
in short
you cannot.
not to the extent some people like to change their form buttons.
best bet is to create another button with an onclick event to press the input type="file" which should be hidden.
you cannot.
not to the extent some people like to change their form buttons.
best bet is to create another button with an onclick event to press the input type="file" which should be hidden.
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
yep.
that is the easiest way ive found to style in these situatuions
that is the easiest way ive found to style in these situatuions
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
•
•
Join Date: Mar 2008
Posts: 10
Reputation:
Solved Threads: 0
This solution (only tested in IE) allows you to replicate type="input" components and apply separate styles to the text box and "Browse..." button.
After submission, you should probably use the path specified in the visibleTextArea as the path to the file to upload because the user will have been able to manually edit this path, so it could be different from the contents of the hiddenFileUpload.
In some implementations of this, you are required to click the submit button twice before the form submits. The onsubmit action included in the code above resolves this problem. I'd be interested to find out why this happens if anyone has an answer.
With a normal type="file" input component, if you type a path into the text area before clicking the browse button, the file chooser that appears will display the directory you specified. The solution above does not replicate this bit of functionality because the value of a type="file" input component can only be set by the user. I assume this is a security measure to stop files being specified programmatically, which would allow a file to be uploaded that was different from the file the user specified.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<form action="#" onsubmit="hiddenFileUpload.disabled = true"> <input type="file" id="hiddenFileUpload" style="display: none;" size="50" accept="*.*" /> <input type="text" id="visibleTextArea" size="50" /> <input type="button" id="visibleBrowseButton" value="Browse..." onclick="hiddenFileUpload.click(); visibleTextArea.value = hiddenFileUpload.value;" /> <br> <br> <input type="submit" value="Submit" /> </form>
After submission, you should probably use the path specified in the visibleTextArea as the path to the file to upload because the user will have been able to manually edit this path, so it could be different from the contents of the hiddenFileUpload.
In some implementations of this, you are required to click the submit button twice before the form submits. The onsubmit action included in the code above resolves this problem. I'd be interested to find out why this happens if anyone has an answer.
With a normal type="file" input component, if you type a path into the text area before clicking the browse button, the file chooser that appears will display the directory you specified. The solution above does not replicate this bit of functionality because the value of a type="file" input component can only be set by the user. I assume this is a security measure to stop files being specified programmatically, which would allow a file to be uploaded that was different from the file the user specified.
Last edited by mowen85; Jun 24th, 2008 at 9:31 pm.
•
•
Join Date: Mar 2008
Posts: 10
Reputation:
Solved Threads: 0
I assume you mean browse button instead of "browser".
This does enable you to change the appearance of the "Browse..." button using CSS.
The code was just an implementation of what I think had already been suggested by Fungus1487:
1) add an input of type="file" and make it hidden.
2) add a visible input of type="text".
3) add a visible input of type="button".
4) set it so that when the visible button is clicked, the hidden browse button is clicked. When a file is selected by the user, copy the value from the hidden text area to the visible one.
Now that you've got two separate components, a text box and a button, that have been arranged to look like the type="file" component, you can apply CSS styling to each of them.
Just add a style="" or class="" attribute to the <input type="button" ... /> in the code I posted before. You'll be able to do things to the button (such as set the background colour) that you previously couldn't do.
I hope that makes sense.
This does enable you to change the appearance of the "Browse..." button using CSS.
The code was just an implementation of what I think had already been suggested by Fungus1487:
1) add an input of type="file" and make it hidden.
2) add a visible input of type="text".
3) add a visible input of type="button".
4) set it so that when the visible button is clicked, the hidden browse button is clicked. When a file is selected by the user, copy the value from the hidden text area to the visible one.
Now that you've got two separate components, a text box and a button, that have been arranged to look like the type="file" component, you can apply CSS styling to each of them.
Just add a style="" or class="" attribute to the <input type="button" ... /> in the code I posted before. You'll be able to do things to the button (such as set the background colour) that you previously couldn't do.
I hope that makes sense.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Dynamic drop down box, populated from MySQL Db
- Next Thread: javascript:Multiple event issue
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate array automatically beta box bug calendar cart checkbox child class codes column createrange() css cursor date debugger decimal design disablefirebug dom download dropdown editor element engine enter error explorer file firefox focus forms frameworks getselection google gwt html htmlform ie8 iframe images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent php player post problem programming progressbar prototype redirect regex runtime safari scale scriptlets scroll search select shopping size sql text textarea toggle w3c web website window windowofwords windowsxp wysiwyg \n





