Results 1 to 4 of 4

Thread: Firefox fires on choose, not on change

  1. #1
    Join Date
    Nov 2009
    Location
    Isfahan, Iran
    Posts
    229
    Thanks
    46
    Thanked 1 Time in 1 Post

    Default Firefox fires on choose, not on change

    Consider this:

    Code:
    <input type="file" id="filePicker">
    <script>
        document.getElementById('filePicker').onchange = function() {
            alert('Hi!');
        };
    </script>
    Even if you choose the same file and the filePicker value doesn't change, you'll see the alert box in Firefox. Any solutions?

  2. #2
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,582
    Thanks
    1
    Thanked 246 Times in 241 Posts

    Default

    Hi there Rain Lover,

    would this possibly meet your requirements...
    Code:
    
    <script>
        var temp;
        document.getElementById('filePicker').onchange = function() {
    if(this.value==temp){
        return;
     }
    else {
       temp=this.value;
       alert('Hi!');
      }
     };
    </script>

    coothead
    ~ the original bald headed old fart ~

  3. The Following User Says Thank You to coothead For This Useful Post:

    Rain Lover (12-15-2015)

  4. #3
    Join Date
    Nov 2009
    Location
    Isfahan, Iran
    Posts
    229
    Thanks
    46
    Thanked 1 Time in 1 Post

    Default

    Thanks for the answer, but would you mind teaching me something: I don't understand return. What does it do in JavaScript? Does it mean "Do nothing"?
    Last edited by Rain Lover; 12-15-2015 at 05:27 AM.

  5. #4
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,582
    Thanks
    1
    Thanked 246 Times in 241 Posts

    Default

    Hi there Rain Lover,

    unfortunately, teaching is not my forte perhaps our resident guru...


    ...could help.

    Alternatively, you could try this...


    Note though, that it could have been coded without it like this...
    Code:
    
    <script>
    (function() {
        'use strict';
        var temp;
        document.getElementById('filePicker').onchange = function() {
    if(this.value!==temp){
       temp=this.value;
       console.log('Hi!'); /* instead of alert('Hi!'); */
      }
     };
    })();
    </script>

    coothead
    ~ the original bald headed old fart ~

Similar Threads

  1. Smooth Navigational Menu - First Item/Anchor Tag Fires on Page Load.
    By DBriars in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 05-04-2012, 08:35 PM
  2. Modal Close fires onLoad/onResize event
    By perl_geek in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 11-03-2011, 12:46 PM
  3. Replies: 2
    Last Post: 03-06-2010, 12:47 PM
  4. Resolved Photo Album Script V2.0 onselectphoto only fires on 1st page
    By jbrooks in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 06-21-2009, 02:35 PM
  5. Script to change pages in Firefox
    By maidus in forum JavaScript
    Replies: 10
    Last Post: 01-04-2007, 08:57 PM

Bookmarks

Posting Permissions

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