9 Replies Latest reply: Feb 12, 2007 7:16 AM by 807574 RSS

    Problem with <Input type = file.../>

    807574
      Hi,
      i have a situation where i would like to use the
      "click()" method of Input Type 'File' control.
      The steps followed by me.
      1.     I put a Input type File control and i made it
      invisible
      2.     I put one Button control and one Text control.
      3.     I am calling the "click()" method of File control
      from the OnClick event of the button control.
      4.     Then i am assigning the File value to the Text
      control.
      5.     I put one more Button control.
      6.     Then Onclick event of this button i am calling
      "SubmitPage" function to submit the page to an target
      asp file.

      When i run this page and on clicking the Send button i
      am getting an error as "Access is denied".
      If u find the solution for this please clarify me.
      Regards
      PSNathan.


      The code used by me :

      <HTML>
      <HEAD>
      <SCRIPT LANGUAGE="Javascript">
      function FileClick()
      {
      document.frmSample.Text1.value =
      document.frmSample.File1.value;
      }

      function SubmitPage()
      {
      document.frmSample.action = "Target.JSP"
      document.frmSample.submit();
      }
      </SCRIPT>
      </HEAD>
      <BODY>
      <FORM Name="frmSample" Method="post" Action="">
      <INPUT Type="file" Name="File1"
      Style="Display:none">
      <INPUT Type="text" Name="Text1" Value="">
      <Input type="button" name="But1" value="Open"
      OnClick=Javascript:File1.click();FileClick()>
      <INPUT Type="button" Name="But2" Value="Send"
      OnClick="SubmitPage()">
      </FORM>
      </BODY>
      </HTML>
        • 1. Re: Problem with <Input type = file.../>
          807574
          ...............
          1 <INPUT Type="text" Name="Text1" Value="">
          2 <Input type="button" name="But1" value="Open"
          3 OnClick=Javascript:File1.click();FileClick()>
          4 <INPUT Type="button" Name="But2" Value="Send"
          5 OnClick="SubmitPage()">
          .................
          i face this problem my friend and i found the solution.
          modify line three to become as this
          OnClick=Javascript:File1.click();FileClick();return false;>
          • 2. Re: Problem with <Input type = file.../>
            807574
            tried using your soln but it is still giving out tha access denied error.
            • 3. Re: Problem with <Input type = file.../>
              807574
              It is my understanding that the .click() method and .value fields are not available for <input type="file"> in some browsers.

              The Mozilla-based browsers like Firefox are one such case. The only solution that appears viable is to make creative use of CSS layers to put the "visible" custom Browse button under the real Browse button and making the real Browse button transparent. That way the user only sees your custom button (not the unstyled Browse button of <input type="file"> and clicks the unstyled one when he thinks he is clicking yours.

              Lame, I know, but it seems to be the only thing that can be done considering the lousy job that the W3C did with styling <input type="file">.

              Good luck.
              • 4. Re: Problem with <Input type = file.../>
                807574
                Hi,
                Can you please let me know if you have got a solution for this problem? I am facing the same problem and have no clue abt what to do.

                Thanks,
                BiS
                • 5. Re: Problem with <Input type = file.../>
                  807574
                  This might solve your problem.
                  http://www.quirksmode.org/dom/inputfile.html.
                  Let me know if it works for you.
                  • 6. Re: Problem with <Input type = file.../>
                    807574
                    Hi,

                    This is the problem because the file which you are trying to upload may
                    be a read only file.

                    thanks
                    Anurag
                    • 7. Re: Problem with <Input type = file.../>
                      807574
                      I am facing a problem which is kind of similar but the problem arises only if the browser is Firefox on WIndows OS. This is while uploading a file with any east asian characters in its filename. IE works fine and uploads the approrpaite file, but Firefox for some reason converts each east asian characters to "_".
                      For E.g., if your file name is 6<3 japanese characters>.txt

                      firefox changes the name as 6___.txt (3 underscore characters). Eventually, the code to upload the file from the directory fails with File NOt Found error, since it is actually looking for a file named "6___.txt"

                      Can somebody help me resolve this issue?[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
                      • 8. Re: Problem with <Input type = file.../>
                        807574
                        hi all,
                        The input type=file cannot be prepopulated, the only way
                        for doing is either clicking browse button directly or type the filename in the box provided beside browse.
                        This has been with the design itself. The intent was to prevent malicious users from, loading files by prepopulating.

                        Regards,
                        Varma
                        • 9. Problem with <Input type = file.../>
                          807574
                          This might solve your problem.
                          http://www.quirksmode.org/dom/inputfile.html.
                          me know if it works for you.
                          Hi -- has anyone made either the css layers or the JS workaround for this work?
                          The author posts his code in snippets and I seem to have missed something....?