Problems with Clearing Input FILE Text Box

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pavan Jha

    Problems with Clearing Input FILE Text Box

    Hi,

    I am using File Input for one of my pages. I have multiple inputs on
    my page as

    <INPUT Type=FILE Name=File1>
    <INPUT Type=FILE Name=File2>
    and so on...

    I have a function for validating filetype which is called on onChange
    of File

    <INPUT Type=FILE Name=FILE1 onchange='retur n
    validatefiletyp e(document.MyFo rm.FILE1)'>

    take a look at the code snippet below for validatefiletpy e

    function validateFileTyp e(thisvalue){
    var i;
    var ufilename;
    if (thisvalue.valu e.length > 0 )
    {

    ufilename = thisvalue.value .toUpperCase();

    var extnarr = ufilename.split (".");

    fileType = "." + extnarr[extnarr.length-1];

    if (fileType == ".GIF")
    {
    thisvalue.value = thisvalue.value .toString();
    return true;
    }
    else
    {

    alert("Only the GIF files are allowed for uploading");
    thisvalue.value = "" ;
    return false;
    }

    }

    }


    Now on to the problem..

    The script runs and works fine till the alert part.. means it does
    flash alert when it finds the wrong format (anything but gif) has been
    chosen for upload... but it doesn't perform the next two steps of
    clearing the File Text box which now shows the selected file name (of
    a non supporting extension, which should be cleared as soon as it
    finds its unacceptable)..

    Can any one tell the reason of this behaviour and how to get it
    working..

    thanks

    p1j
  • Martin Honnen

    #2
    Re: Problems with Clearing Input FILE Text Box



    Pavan Jha wrote:

    [color=blue]
    > I am using File Input for one of my pages. I have multiple inputs on
    > my page as
    >
    > <INPUT Type=FILE Name=File1>
    > <INPUT Type=FILE Name=File2>
    > and so on...
    >
    > I have a function for validating filetype which is called on onChange
    > of File
    >
    > <INPUT Type=FILE Name=FILE1 onchange='retur n
    > validatefiletyp e(document.MyFo rm.FILE1)'>
    >[/color]
    [color=blue]
    > alert("Only the GIF files are allowed for uploading");
    > thisvalue.value = "" ;
    > return false;[/color]
    [color=blue]
    > The script runs and works fine till the alert part.. means it does
    > flash alert when it finds the wrong format (anything but gif) has been
    > chosen for upload... but it doesn't perform the next two steps of
    > clearing the File Text box which now shows the selected file name (of
    > a non supporting extension, which should be cleared as soon as it
    > finds its unacceptable)..
    >
    > Can any one tell the reason of this behaviour and how to get it
    > working..[/color]

    It is simple, script is not allowed to set the value of the <input
    type="file"> element object as that way you could upload files from the
    browser user's file system without the user selecting.

    --

    Martin Honnen


    Comment

    Working...