473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How To Style The <input type="file /> Tag With CSS

dmjpro
2,476 2GB
When the browser encounters
Expand|Select|Wrap|Line Numbers
  1. <input type = file>
Then a text box followed by a button appears on the browser window.

What i want to do:
Change the separate styles of the two elements as in DOM it is treated as a single one.

Can i do this using style sheet?
Feb 24 '07 #1
12 120508
AricC
1,892 Expert 1GB
when browser encounters ..

<input type = file>
then a text box follwed by a button appears on the browser window.

now what i want to do that ...
change the seperate styles of the two elements as in DOM it is treated as a single one...

can i do this using stylesheet?????

thanx in advance........
I don't see why not give them both the same class.
Feb 24 '07 #2
dmjpro
2,476 2GB
sorry...

i don't understand ur point of view
Feb 25 '07 #3
dmjpro
2,476 2GB
friends ......

i got a temporary solution .......


<input type = file name = browse style = 'display:none'>
<input name = file_name>
<input type = button onclick = 'browse.click();file_name.value = browse.value'>

here i can change the style of last two elements which are two seperate elements in html page .....
the button will work on behalf of the file input tag ....which is invisible ...

but here is a page submitting problem ......

i m trying to slove it now ....

if i slove it then i send u in details .........

best of luck friends ......
Feb 27 '07 #4
AricC
1,892 Expert 1GB
friends ......

i got a temporary solution .......


<input type = file name = browse style = 'display:none'>
<input name = file_name>
<input type = button onclick = 'browse.click();file_name.value = browse.value'>

here i can change the style of last two elements which are two seperate elements in html page .....
the button will work on behalf of the file input tag ....which is invisible ...

but here is a page submitting problem ......

i m trying to slove it now ....

if i slove it then i send u in details .........

best of luck friends ......
DMJPRO,
What are you trying to do now I'm completely lost. Are you trying to get the location of a file and style the text box + button? I'll see if I can work up an example. Perhaps a link to the page would help.

Aric
Feb 27 '07 #5
AricC
1,892 Expert 1GB
when browser encounters ..

<input type = file>
then a text box follwed by a button appears on the browser window.

now what i want to do that ...
change the seperate styles of the two elements as in DOM it is treated as a single one...

can i do this using stylesheet?????

thanx in advance........
DMJ,
I tried this:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2.     <html>
  3.         <head>
  4.             <title>Test File</title>
  5.                 <style type="text/css">
  6.  
  7.         .clsFile
  8.                 {
  9.         border: 1px solid black;
  10.         background-color: red;
  11.         }
  12.  
  13.         </style>
  14.         </head>
  15.             <body>
  16.         <form action="#">
  17.                <input type="file" class="clsFile" />
  18.         </form>
  19.             </body>
  20. </html>
  21.  
Now I see what you mean check out this I think it should help.
Feb 28 '07 #6
dmjpro
2,476 2GB
thanx for ur replyyyyyy ......

a good link u sent ...........

again a lot of thanx ........
Feb 28 '07 #7
AricC
1,892 Expert 1GB
thanx for ur replyyyyyy ......

a good link u sent ...........

again a lot of thanx ........
No problem as soon as I tried to style the input file I realized what you meant.


Aric
Feb 28 '07 #8
This script will let you use an image for the 'Browse...' button and style the textbox. It also clears the path name from both the file and text tags so they stay in synch. I also have it so the image path is displayed on submit so you can see it is working... take that out when you use it.

<html>
<head>
<script type="text/javascript">
function setPath(f) {
document.getElementById('mypath').value = f;
}
function browse() {
document.getElementById('realFile').click()
}
function clearIt(f) {
f.value='';
var d = document.getElementById('browser');
var olddiv = document.getElementById('realFile');
var new_element = document.createElement( 'input' );
new_element.type = 'file';
new_element.id='RealFile';
new_element.onchange = function() {document.getElementById('mypath').value = document.getElementById('realFile').value;};
d.replaceChild( new_element,olddiv );
}
</script>
</head>
<body>
<form onsubmit="alert(document.getElementById('realFile' ).value);return false;">
<input type="text" style="width=300px;border:solid 1px #0000FF" id="mypath" onfocus="clearIt(this)">
<a href=#" onclick="browse()"><img src="d.gif" border=0></a>
<div id="browser" style="display: none">
<input type="file" id="realFile" onchange="setPath(this.value)"><p>
</div>
<input type="submit" >
</form>
</body>
</html>
Apr 4 '07 #9
macsig
1
Hi Mike, your code is great but it doesn't work.
When I click the image it doesn't open any browsing window.

Do you any idea about that?

THANKS
Feb 17 '08 #10
drhowarddrfine
7,435 Expert 4TB
1) You want to ask this question on the javascript board.
2) This thread is a year old.
Feb 18 '08 #11
This is one of the smart answer for your problem...




<input type = file name = browse style = 'display:none' onchange="file_name.value = browse.value">


<input name = file_name >

<input type = button onclick = 'browse.click();'>




Got it friends......
Mar 27 '13 #12
r035198x
13,262 8TB
The thread was already very old in 2008. We are now in 2013 ...
Mar 27 '13 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jesper Hermansen | last post by:
Hi! I'm making a system that will generate Winamp-playlists. To make it easy for the user to add a file to the list, I'm using <input type="file">. The problem with this is that I only get...
2
by: Matt | last post by:
If I do the following, the browse text box still cannot see C:/hello world/test.txt. <input type="file" name="fileName" value="C:/hello world/test.txt" size=80> Any ideas? and workarounds...
2
by: Laermans_k | last post by:
Hi, Does anyone have a solution to use the <input type="file" id="filechooser"> and the <input type="submit" id="submitbutton"> in 1 button click? I've already tried to create a javascript...
7
by: Drew Berkemeyer | last post by:
I've encounted a pretty strange problem and I'm not quite sure what to make of it. I have a web service that consumes an XML file as well as a few other parameters. This web service works fine...
2
by: Tarkeshwar | last post by:
Hi All, I want to restrict the user from being entering the value in <input type="file">. It works fine in IE but not in Mozilla. I am sending my code also which works in IE and not in Mozilla.Can...
7
by: Tim Slattery | last post by:
I'm trying to handle the onChange event in an <input type="file"> element. In IE, there's no problem: the event fires when a file in the "open" box is doubleclicked, or the "Open" button in the box...
3
by: eeeeman | last post by:
This one has really got me! Im trying to write a value to a input type="file" form element using client-side javascript. I have tried the obvious, simply writing: <input type="file" ...
1
by: ChollaPete | last post by:
This code: <form action="processScan.php" method="get"> <p> <?php print "Scan name: <input type=\"file\" name=\"tScanFileName\" value= \"{$scanFileName}\"><br>"; addHiddenCarryons(); ?>...
1
by: sandeep kumar shah | last post by:
Hi, We have used a file uploading HTML tag in an HTML page. We need to customize the text displayed on the Button (which is by default “Browse…” for internet explorer). Below is the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.