disabling filename input

  • Thread starter Thread starter Vikram
  • Start date Start date
V

Vikram

How can i restrict user from entering anything in file name of input type
file (upload) control. I want user can ionly select file using browse button
 
Techincally, you cannot do this in the literal sense. This is controlled by
the browser. You could suggest that your user uses Opera, as I believe that
only gives the option to browse.

There are tricks you can play to get the effect you're after, though. Take
a look here. http://www.quirksmode.org/dom/inputfile.html

Ray at work
 
The browser controls file selection in a rather authoritative manner because
it is a very sensitive area from a security standpoint. Therefore there is
no way to do this with HTML alone. You'd need an ActiveX control or some
other thick client that has been granted permission to handle such matters.
 
You could use client side scripting, if you capture the keydown (onkeydown)
event of the file control then you can return without updating the text
element.

in your form 'body' define the following:
<body onkeypress="return onkeyPress(event);">

then you can write script to return onkeypress (I use javascript)

function onkeyPress(e)
{
var key = window.event ? e.keyCode : e.which;
if (key == 13)
StartClick();

e.cancelBubble = true;
e.returnValue = false;
return false;
}

the above will return and and not update any controls. However if 'Enter' is
pressed it will run the 'StartClick' funtion.
 
just a warning this will effect all other input controls on the form you may
be better adding the keypress event to just the 'file' control.e.g.
<INPUT type="file" onkeypress="return onkeyPress(event);">
 
Back
Top