Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2003
    Posts
    106

    Unanswered: Urgent:<input type="file"> IE Incompatabilities

    We are using ASP to upload a file.

    We have <input type="file"> which allows the user to choose a file.

    But user can type any junk into the file text box and when he clicks on Upload button it uploads an empty file with the junk given as file name.

    We need to prevent this.I can use <input type="file" READONLY>,But this works fine on IE5 but on IE6,the Browse button does not open the dialog box at all.

    Do you have any workaround for this which will work on both IE5 and IE6.

    Its urgent
    Sachi

  2. #2
    Join Date
    Dec 2003
    Posts
    454
    What is the component you are using to upload file? Usually you can check the file size, extension and so on. You do not need to put READONLY there.

  3. #3
    Join Date
    Jan 2003
    Posts
    106

    yes

    Hi,

    You are right,But I want to prevent users from typing some junk into the file text box.How shall I do it then???
    Sachi

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    try this....

    <body>
    <form name="frmTest" id="frmTest">
    <input type="file" onkeydown="return false;" onkeypress="return false;" id="testfile">
    </form>
    </body>

    you can still right click and cut or paste from the field, but if you using onmousedown it theory you should be able to disable that as well.
    Last edited by rokslide; 04-07-04 at 02:05.

  5. #5
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    new version for you....
    Code:
    <script>
    function test(){
    	if(window.event.button==2) {
    		alert('Please use the browse button');
    		return false;
    	}
    	else {
    		return true;
    	}
    }
    </script>
    <body>
    <form name="frmTest" id="frmTest">
    <input type="file" onmousedown="return test();" onkeydown="return false;" onkeypress="return false;" id="testfile">
    </form>
    </body>
    tested under ie 5.5

  6. #6
    Join Date
    Jan 2003
    Posts
    106

    thanx rokslide

    Thanx a lot rokslide,

    You have solved out problem,

    I hope this thread wil be very usefull for many guys facing the same problem over the net.
    Sachi

  7. #7
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    It's probably possible to fake the page of course and try to submit a file that doesn't exist.... there is nothing you can really do about that though.... and I very much doubt it will work with Netscape/Mozilla/Gecko browsers....

    But for your problem it should be fine....

  8. #8
    Join Date
    Jan 2003
    Posts
    106

    is it possible to allow just left and right arrows

    This works fine but

    The user will not be able to see the entire path in the file text box after choosing the file using Browse button,since he cannot use arrow keys,is it possible to allow just arrow keys so that user can see the entire path but not able to type any characters.

    Only if possible otherwise its ok.
    Sachi

  9. #9
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    try this.....
    Code:
    <script>
    function test(){
    	if(window.event.button==2) {
    		alert('Please use the browse button');
    		return false;
    	}
    	else {
    		return true;
    	}
    }
    function test2(){
    	if(window.event.keyCode==37||window.event.keyCode==39){
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    </script>
    <body>
    <form name="frmTest" id="frmTest">
    <input type="file" onmousedown="return test();" onkeydown="return test2();" onkeypress="return test2();" id="testfile">
    </form>
    </body>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •