Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Open Files

  1. #1
    New to the CF scene
    Join Date
    Feb 2003
    Location
    São Paulo - Brazil
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Open Files

    Hello all,

    I have 2 problems, listed bellow:

    1-) I'd like to use a open file dialog in my program, but I don't know the code in JavaScript that get me this function.
    2-) I have an <INPUT type=FILE> in my page and I tried to set the value using the property value of this object of many ways: by JavaScript (document.form1.file1.value = 'xxxx') and manually, but nothing works, have anyone experienced this situation before! What should I do?

    Thanks any help.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You don't set the value of a <input type="file"> tag. You can only get the value as set by the client, if your script could set the value websites could easily get any file they wanted from the client's computer, often without the user even knowing they've been robbed. It's a security thing, the browser will never let you set the value.

  • #3
    New to the CF scene
    Join Date
    Feb 2003
    Location
    São Paulo - Brazil
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dear,

    Thanks for your reply, and for the 1st. question, do you have any trip???

    Thanks.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually my response was to part 2 of your question, the <input type="file" /> tag you were using is the answer for part 1 of your question. The key thing to know is that you cannot script that form field for the user, they'll have to use that input field to navigate to the file themselves. That usually means some rather detailed instructions depending on the level of the users.

  • #5
    New Coder
    Join Date
    Sep 2002
    Location
    Moncton, N.B., Canada
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's much better to open files with a server-side language but if you must have a client-side solution here is an (IE) ActiveX object. Due to security, you will receive a prompt.. only by clicking yes will the file be loaded.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function readFile(f) 
    {
      var fso = new ActiveXObject('Scripting.FileSystemObject');
      var fs = fso.OpenTextFile(f);
      document.formName.fileContent.value = fs.ReadAll();
    }
    </script>
    </head>
    <body>
    <form name="formName">
    <br />
    <textarea name="fileContent" rows="20" cols="100%"></textarea>
    <br />
    <input type="file" size="40" onchange="readFile(this.value)" />
    </form>
    </body>
    </html>


  •  

    Posting Permissions

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