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 or have the form submit as normal.
I have found that the same question was asked here with no answer: http://www.webmasterworld.com/html/3290988.htm
And this person came up with a hack which I can use if there is no other suitable answer: http://www.shauninman.com/archive/2007/09/10/styling_file_inputs_with_css_and_the_dom
EDIT: To clarify – if the user types ‘not a file path’ in the text box next to the ‘Browse’ button and clicks submit, in IE nothing will happen. The form will not submit – IE does not allow a form to be submitted when a <input type=’file’> box does not have a real file path.
I solved this with another way using a button rather than a submit and using JavaScript to check the value before submitting.
I realise there still needs to be server-side validation for the file but this is only to prevent a user clicking on the Submit button and not seeing anything happening. Also, it assumes IE using a Windows OS.