Tuesday, December 20, 2011

Making the input file box readonly in IE

Is it possible to prevent a user from typing in a file input text box in IE? The reason I ask is that if a user enters text that does not look like a file system path (eg. doesn't start with something like c:...) then when the user clicks the submit button nothing will happen.

I would either like to not allow the user to type in the box


SOLUTION

<input 
type="file" 
name="file" 
onKeyDown="this.blur()" 
onContextMenu="return false;">

In IE 7.0 and IE8.0 this fix is not required. As it has already been made readonly by Microsoft. This fix is specifically required for IE 6.0

No comments:

Post a Comment