SitePoint Sponsor

User Tag List

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

    submitting the form upon file selection

    Hello

    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:"document.myForm.file.click"
    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:
    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="this.form.file.click();">
      <input type="text" name="text">
      <input type="submit" value="submit">
    </form>
    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.

    thanks

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


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
  •