faruquis
asked on
Disable Txt Filed of fileupload
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-da ta">
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
<FORM ACTION="" METHOD="post" ENCTYPE="multipart/form-da
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
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
You could just use a hidden field instead.?
A better question, would be Why?
Rockman
<INPUT TYPE="file" NAME="file" onkeydown="return false;" />
You can't script that type of field. It's a security thing.
you can't change the value of the control with script, but you can set key handler functions as shown.
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?
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?
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
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
here we go!
onkeydown="this.click();re turn false;"
onkeydown="this.click();re
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!
scratch that last comment ... they won't be able to "ok" out of it unless they choose a valid filename :)
Maybe something like this:
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM ACTION="" METHOD="post" ENCTYPE="multipart/form-da ta">
File1 : <INPUT TYPE="file" NAME="file" ID="file" onKeyPress="javascript: this.blur();this.click();" ><br>
</form>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM ACTION="" METHOD="post" ENCTYPE="multipart/form-da
File1 : <INPUT TYPE="file" NAME="file" ID="file" onKeyPress="javascript: this.blur();this.click();"
</form>
</BODY>
</HTML>
again, you don't need the javascript: modifier in event handlers
onKeyPress="this.blur();th is.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.
onKeyPress="this.blur();th
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.
... which goes back to your original question sean :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
thanks very much.
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.
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.
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM ACTION="" METHOD="post" ENCTYPE="multipart/form-da
File1 : <INPUT TYPE="file" NAME="file" ID="file" onKeyPress="javascript: this.blur()"><br>
</form>
</BODY>
</HTML>