www.webdeveloper.com
Results 1 to 5 of 5

Thread: File Input Clear Or Reset Help Needed

  1. #1
    Join Date
    Apr 2008
    Posts
    4

    Question File Input Clear Or Reset Help Needed

    I am trying to pull a value from a file input form and now all i want to do is reset or clear the value before the page gets submitted and the file input value is posted.


    does anyone know how to do this??




    <html>
    <head>
    <script type="text/javascript">

    function submitform()
    {
    var empty = ""
    var olly = document.myform["upload"].value;
    if (olly == "")
    {
    //do submit
    alert("form empty submit");
    document.myform.submit();
    }
    else if (olly !="")
    {
    alert("not empty clear then submit");

    //document.myform["upload"].reset();
    //document.getElementById("myForm").elements["upload"].reset();
    //document.myform.upload.value=null;
    //document.myform["upload"].value = "";
    //document.myform.getElementByName("upload").resetupload();
    //document.getElementByName("upload").elements["upload"].value = "";
    //document.myform.submit();
    }

    alert(olly);
    }
    </script>

    </head>
    <body>
    <form name="myform" enctype="multipart/form-data" method="post" action="clear_test.php">
    <p>
    <input type="hidden" id="max" name="max" value="52428800" />
    <input type="hidden" name="file" />
    <input type="file" name="upload" id="uploadid" size="30" title="Browse for a File to Upload.">

    <SELECT NAME="multiple_select" id="multiple_select" onChange="submitform();">
    <OPTION VALUE="option1">option1</OPTION>
    <OPTION VALUE="option2">option2</OPTION>
    <OPTION VALUE="option3">option3</OPTION>
    <OPTION VALUE="option4">option4</OPTION>
    <OPTION VALUE="option5">option5</OPTION>
    <OPTION VALUE="option6">option6</OPTION>
    </SELECT>
    <input type="submit" name="submit1" value="Submit" >
    </p>
    </form>
    </body>
    </html>

  2. #2
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,755

  3. #3
    Join Date
    Apr 2009
    Posts
    10
    Here is very good solution for this problem:
    http://gusiev.com/?p=11

  4. #4
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,755
    That solution works just fine as long as you don't need to refer to that file input field in JavaScript using the form.elements.field_name syntax. When you add form fields to the DOM via innerHTML, the elements array of a FORM object does not get updated.

  5. #5
    Join Date
    Apr 2009
    Posts
    10
    Good to know.
    By I prefer to get elements by id.
    I don't think that fault described by you is a big problem.

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