SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast mohammedsk's Avatar
    Join Date
    Nov 2005
    Location
    Columbia, Missouri
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replace browse button and file input

    Hi,
    I have this code which is suppose to replace the browse button and file input in HTML form.
    It works fine in IE, but not in Firefox.
    The problem is that the statement browse.click() that you will see in the code
    does not get triggered in Firefox.

    Code:
    <form name="test_form" method="post" action="testu.php" enctype="multipart/form-data">
    <input type="file" name="browse" style="display: none;">
    <input type="text" name="file" value="<?= $_POST['file']; ?>" >
    <input type=button
    style="font-style:veranda; font-size:12px; font-weight:bold;text-transform:lowercase;color:white;background-color:#A2C382;height:22px;border-style:ridge;text-align:center;"
    onClick="browse.click();file.value=browse.value; browse.disabled=true;" 
    value="Select a File...">
    <br><br>
    <input type="submit" name="upload_photo"
    value="Submit The Form Now!"
    style="font-style:veranda; font-size:12px;">
    </form>
    That is a link for the code, so you can see the demo.
    http://www.vitaladventure.com/mohammed/testu.php

    Any help is appreciated,
    Thanks

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firefox doesn't support the click method on file inputs. I don't know if this is broken or done in purpose, since the click method does exist for the file input. It just doesn't do anything.

  3. #3
    SitePoint Enthusiast mohammedsk's Avatar
    Join Date
    Nov 2005
    Location
    Columbia, Missouri
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is frustrating.

    Thanks for the reply,

  4. #4
    SitePoint Enthusiast mohammedsk's Avatar
    Join Date
    Nov 2005
    Location
    Columbia, Missouri
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there any other way do it?
    What I am trying to do, is to keep the file path visible for the user. So when an error occurs when the form is submitted and the page reloads the file path does not disappear from the box so that user does not have to browse again.

    I hope that make sense.

  5. #5
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, it works like this due to security reasons. Sorry

  6. #6
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •