SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2004
    united states
    0 Post(s)
    0 Thread(s)

    submitting the form upon file selection


    I have a form with several input tags. One of them is a type=file tag.
    I would like the form to be submitted automatically as soon as the user chooses a file.

    I tried to change the appearance of the file input but making it invisible, and placing a regular button on top of it. upon the onclick of the button I invoked:""
    This seemed to open the file dialog. will this solution work?
    I heard that for security reason, the file input tag cannot be overriden.

    Here is a sample of my code:
    <form name="myForm" method="post" action="target.php" enctype="multipart/form-data">
      <input type="file" id="file" name="file" style="display:none" onchange="this.form.submit()">
      <input type="button" value="click to pick a file" onclick=";">
      <input type="text" name="text">
      <input type="submit" value="submit">
    The user will have two ways of submitting the form:
    * clicking the 'submit' button
    * selecting a file using the file selector - this should automatically submit the form.

    The problem is the when I choose a file, I get a JavaScript error saying: access is denied.

    I would like also to make sure that the user can only select files of a certain extension from the file select dialog. i.e; image/jpeg, image/png, image/gif
    Is there a way of setting those extensiosn for the file dialog?
    I heard about the accept attribute, but read somewhere that it is ignored by the browser.


  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    0 Post(s)
    0 Thread(s)
    [ already answered / other board ]
    ::: certified wild guess :::


Posting Permissions

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