Web Analytics Made Easy -
StatCounter Setting input type="file" value via Javascript - CodingForum

Announcement

Collapse
No announcement yet.

Setting input type="file" value via Javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting input type="file" value via Javascript

    Basically I have a text input and a file input. I want to take the value of the text input and stick it in the file input. Simple HTML + Javascript is:

    <input type="text" id="myText" />
    <input type="file" id="myFile" />

    <script type="text/javascript">
    function doIt() {
    var textInput = document.getElementById("myText");
    var fileInput = document.getElementById("myFile");

    fileInput.value = textInput.value;
    }
    </script>

    This seems like a pretty simple thing to want to do but I guess it's a security no-no (?)... Firefox says:

    "Exception: "security error" code : "0x805303e8 (NS_SECURITY_DOM_SECURITY_ERR)" location... line 56

    Anyone know a way to get this to work?

  • #2
    Read what its telling you.
    Originally posted by Firefox
    "Exception: "security error" code : "0x805303e8 (NS_SECURITY_DOM_SECURITY_ERR)" location... line 56
    Its a security issue. Because of how sensitive that field is you aren't allowed to set its value.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

    Comment


    • #3
      Are you trying to make a custom file input? If so there are workarounds for that, but not in the way that you are attempting.
      Helping to build a bigger box. - Adam Matthews

      Comment


      • #4
        I'm afraid it is impossible to set a default value for file input. If you could, it would be a huge security risk because you can just upload any file on the user's computer on to yours without their notice even (with Javascript submit() and stuff).

        Comment

        Working...
        X