Events for input type="file"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • @lias

    #1

    Events for input type="file"

    Hi all

    I have a webpage where I want the user to input filenames. To make this easier,
    I use a file input type so that the user can select files rather than typing in
    the filename, using the HTML below.

    <input type="file" size="25" maxlength="256" id="filename" onchange="AddFi le()"
    />

    The problem I have is that the javascript function AddFile() is only run under
    Internet Explorer, and not under Mozilla. I need the function to run each time a
    file is selected as the filenames are added to a text box (the user is creating
    a list of files).

    Is there some way of having this work under Mozilla?

    Thanks.


  • Michael Winter

    #2
    Re: Events for input type=&quot;file &quot;

    On Sun, 4 Apr 2004 01:42:25 +1200, @lias
    <kix_pet@yahoo. spammers.go.her e.com> wrote:
    [color=blue]
    > I have a webpage where I want the user to input filenames. To make this
    > easier, I use a file input type so that the user can select files rather
    > than typing in the filename, using the HTML below.
    >
    > <input type="file" size="25" maxlength="256" id="filename"
    > onchange="AddFi le()" />
    >
    > The problem I have is that the javascript function AddFile() is only run
    > under Internet Explorer, and not under Mozilla. I need the function to
    > run each time a file is selected as the filenames are added to a text
    > box (the user is creating a list of files).[/color]

    The onchange event works very strangly with file-type INPUTs when the
    "Browse" button is used. It doesn't fire at all in Mozilla, and the
    control must lose focus for it to fire in Netscape. It fires as you expect
    it to with Opera and IE. When changed via the keyboard, all of these
    browsers will fire the event once the control loses focus.
    [color=blue]
    > Is there some way of having this work under Mozilla?[/color]

    Use the onclick event in tandem with onchange. You'll have to keep a
    record of the previous value though, to see if the value was indeed
    changed, or if the control was simply clicked. A better alternative is to
    use a separate button to call the AddFile() function.

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • @lias

      #3
      Re: Events for input type=&quot;file &quot;


      "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
      news:opr5xumvqc 5vklcq@news-text.blueyonder .co.uk...[color=blue]
      > On Sun, 4 Apr 2004 01:42:25 +1200, @lias
      > <kix_pet@yahoo. spammers.go.her e.com> wrote:
      >[color=green]
      > > I have a webpage where I want the user to input filenames. To make this
      > > easier, I use a file input type so that the user can select files rather
      > > than typing in the filename, using the HTML below.
      > >
      > > <input type="file" size="25" maxlength="256" id="filename"
      > > onchange="AddFi le()" />
      > >
      > > The problem I have is that the javascript function AddFile() is only run
      > > under Internet Explorer, and not under Mozilla. I need the function to
      > > run each time a file is selected as the filenames are added to a text
      > > box (the user is creating a list of files).[/color]
      >
      > The onchange event works very strangly with file-type INPUTs when the
      > "Browse" button is used. It doesn't fire at all in Mozilla, and the
      > control must lose focus for it to fire in Netscape. It fires as you expect
      > it to with Opera and IE. When changed via the keyboard, all of these
      > browsers will fire the event once the control loses focus.
      >[color=green]
      > > Is there some way of having this work under Mozilla?[/color]
      >
      > Use the onclick event in tandem with onchange. You'll have to keep a
      > record of the previous value though, to see if the value was indeed
      > changed, or if the control was simply clicked. A better alternative is to
      > use a separate button to call the AddFile() function.
      >
      > Mike
      >
      > --
      > Michael Winter
      > M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)[/color]

      Thanks for your help Michael. I guess I'll stick with adding a separate button.


      Comment

      Working...