473,383 Members | 1,846 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,383 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 120507
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.