dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: html type="file" do not want auto submit

  1. #1
    Join Date
    Mar 2011
    Posts
    4

    html type="file" do not want auto submit

    Hi everyone,

    i have a form which has input type="file" in it. When a file is selected I store the file path using javascript for use in my script. My problem is that once the file selection window opens, if the window is closed without selecting a file the form automatically gets submitted. It doesn't do this if a file IS selected.

    All I really need is an input type that allows selection of a filepath without doing an upload which is what type="file" is for, BUT I don't think what I need exists???

    Alternatively I need my form to NOT be automatically submitted when the user has not selected a filepath. Any way of doing this?

    Thanks in advance.

  2. #2
    Join Date
    Nov 2010
    Location
    Los Angeles, CA
    Posts
    234
    Do you have a link? I don't think there is any form that automatically submits unless there is javascript that does the submission.

  3. #3
    Join Date
    Mar 2011
    Posts
    4
    I do not have a link as I am developing locally.

  4. #4
    Join Date
    Nov 2010
    Location
    Los Angeles, CA
    Posts
    234
    As far as I know, a simple <input file="type"> element will not submit a form on its own. Either the user selects a file or clicks cancel/X to close the dialog. After either of these, the form will still not submit until the user does so. You may have some javascript submitting the form on its own. A form gets submitted either by the user clicking the submit button or custom javascript firing off the submit event.

  5. #5
    Join Date
    Mar 2011
    Posts
    4
    Thanks Big O I will double check my code and post back.

  6. #6
    Join Date
    Mar 2011
    Posts
    4

    resolved

    OK I have cut down the code to the bare bones and it still does it. It seems to submit the form when using javascript to trigger the click event on the type=file field. Clicking on the type=file field itself does not submit the form.

    Here is the code:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>
    </head>
    <body>
    <form name = "entry" action = "insert.php" method = "post">
    <table>
    <tr>
    <td>
    <input type="file" name="image_filename" id="file"/>
    <input id="uploaded_image" type="image" src=""
    onClick="image_filename.click()"/>
    </td>
    </tr>
    <tr>
    <td>
    <button type="submit" id="save_your_item"
    name="save_your_item">
    Submit
    </button>
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles