Solved

Disable Txt Filed of fileupload

Posted on 2004-08-31
17
793 Views
Last Modified: 2012-05-11
I want to disable the text field in which filepath is shown in the text box of the following code

<FORM ACTION="" METHOD="post"  ENCTYPE="multipart/form-data">
File1 : <INPUT TYPE="file" NAME="file"><br>


I dont want to allow the user to type in the text field provided by html which shows the file name as selected by the browse buttion. Please help !

Nabeel
0
Comment
Question by:faruquis
17 Comments
 
LVL 8

Expert Comment

by:RozanaZ
ID: 11941141
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM ACTION="" METHOD="post"  ENCTYPE="multipart/form-data">
File1 : <INPUT TYPE="file" NAME="file" ID="file" onKeyPress="javascript: this.blur()"><br>
</form>
</BODY>
</HTML>
0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 11941264
If you dont want anyone to type in it, why do you have it there?
You could just use a hidden field instead.?

A better question, would be Why?

Rockman
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11941372

 <INPUT TYPE="file" NAME="file" onkeydown="return false;" />
0
 
LVL 19

Expert Comment

by:webwoman
ID: 11941717
You can't script that type of field. It's a security thing.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11941755
you can't change the value of the control with script, but you can set key handler functions as shown.
0
 
LVL 31

Expert Comment

by:seanpowell
ID: 11942119
Absolutely...

kEk, I've always used the onkeydown="return false;", is that preferred over onKeyPress="javascript: this.blur()" ?
I'm just curious about using one over the other?
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11942159
actually, I never tried onKeyPress="this.blur()" until just now (the javascript: modifier is not needed in an event handler)
both do the job adequately. It would be nice if instead of just blurring the field the focus could be put on the browse button ... hmmm
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11942366
here we go!  

onkeydown="this.click();return false;"
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 33

Expert Comment

by:knightEknight
ID: 11942389
of course, even if you force the user to click on the "Browse" button, they can still type in the "file name" field of the Browse dialog!
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11942402
scratch that last comment ... they won't be able to "ok" out of it unless they choose a valid filename :)
0
 
LVL 8

Expert Comment

by:RozanaZ
ID: 11942534
Maybe something like this:

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM ACTION="" METHOD="post"  ENCTYPE="multipart/form-data">
File1 : <INPUT TYPE="file" NAME="file" ID="file" onKeyPress="javascript: this.blur();this.click();"><br>
</form>
</BODY>
</HTML>
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11942582
again, you don't need the javascript: modifier in event handlers

  onKeyPress="this.blur();this.click();" />

using .blur() in this case is actually a better solution because it allows you to tab out of the control once a file has been selected.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11942586
... which goes back to your original question sean :)
0
 
LVL 8

Accepted Solution

by:
RozanaZ earned 50 total points
ID: 11942662
Agree with you, knight

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM ACTION="" METHOD="post"  ENCTYPE="multipart/form-data">
File1 : <INPUT TYPE="file" NAME="file" ID="file" onKeyPress="this.blur();this.click();"><br>
</form>
</BODY>
</HTML>
0
 

Author Comment

by:faruquis
ID: 11943168
i need to develop an application without javascripts... to make it browsers compatible.. please give me some html solution if possible. Thanks for all your comments.. :)
thanks very much.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11943231
There is no HTML only solution for this problem since the file control is implemented in HTML.  You might be able to find a plug-in to do this, but then you have the problem of browser compatibility again.  The script listed above is very simple and supported by the latest versions of nearly all browsers, so compatibility will be less of an issue using the script above.
0
 
LVL 1

Expert Comment

by:Dan-LL
ID: 20836661
This does not solve the problem, it works that the user can't type junk in the text box because it forces the "open a file" box but once you return to the form you can delete some on the text that has appeared i.e the path and filename which still causes your control code to fail as the textbox is invailid.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Zoom web page in asp.net 2 36
How to convert code to a png file 22 101
jQuery value within div undefined 3 21
Modify Table Width 6 13
Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now