Hiding input type=file, access denied error

Discussion in 'Javascript' started by hrpreet, Oct 17, 2006.

  1. hrpreet

    hrpreet Guest

    Hi All,

    I need the file chooser in the jsp, just for brosing and saving the
    file path in the database, so i have used the following code.I dont
    need to read the file content. I have to make it hidden because in
    edit mode i need to show the field prepopulated with the file path,
    which doesnot happen with input type=file, it cant be shown
    prepopulated. But the following code gives access denied error.Please
    help.

    <html>
    <head>
    <script>
    function browseFile(){

    document.form.browse .click();
    document.form.filename.value=document.form.browse.value;
    return true;
    }
    </script>
    </head>
    <body>
    <form name="test_form" method="post" action="test.jsp">
    <input type=file name=browse style="display: none;">
    <input type=text name=filename>
    <input type=button value="Select a File..." onClick="browseFile();">


    <input type=submit value="Submit The Form Now!">
    </form>
    </body>
    </html>

    Thanks for help.
     
    hrpreet, Oct 17, 2006
    #1
    1. Advertising

  2. hrpreet

    marss Guest

    hrpreet напиÑав:
    > Hi All,
    >
    > I need the file chooser in the jsp, just for brosing and saving the
    > file path in the database, so i have used the following code.I dont
    > need to read the file content. I have to make it hidden because in
    > edit mode i need to show the field prepopulated with the file path,
    > which doesnot happen with input type=file, it cant be shown
    > prepopulated. But the following code gives access denied error.Please
    > help.
    >
    > <html>
    > <head>
    > <script>
    > function browseFile(){
    >
    > document.form.browse .click();
    > document.form.filename.value=document.form.browse.value;
    > return true;
    > }
    > </script>
    > </head>
    > <body>
    > <form name="test_form" method="post" action="test.jsp">
    > <input type=file name=browse style="display: none;">
    > <input type=text name=filename>
    > <input type=button value="Select a File..." onClick="browseFile();">
    >
    >
    > <input type=submit value="Submit The Form Now!">
    > </form>
    > </body>
    > </html>
    >
    > Thanks for help.


    document.test_form.browse.click();
    document.test_form.filename.value=document.test_form.browse.value;
     
    marss, Oct 17, 2006
    #2
    1. Advertising

  3. hrpreet

    Randy Webb Guest

    hrpreet said the following on 10/16/2006 11:27 PM:
    > Hi All,
    >
    > I need the file chooser in the jsp, just for brosing and saving the
    > file path in the database, so i have used the following code.I dont
    > need to read the file content. I have to make it hidden because in
    > edit mode i need to show the field prepopulated with the file path,
    > which doesnot happen with input type=file, it cant be shown
    > prepopulated. But the following code gives access denied error.Please
    > help.


    You get that error message because you can't programatically set the
    value of a file input element. It's a security violation.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices -
     
    Randy Webb, Oct 17, 2006
    #3
  4. hrpreet

    Tim Slattery Guest

    Randy Webb <> wrote:

    >You get that error message because you can't programatically set the
    >value of a file input element. It's a security violation.


    He's not trying to. He's retrieving the value of the <input
    type="file"...> and assigning that to an <input type="text"...>
    element.

    Why he needs to do that, I don't understand. The "file" element
    includes a text box that gets set to the name of the file selected. It
    seems that would show the exact same thing that he's trying to show in
    his "text" box.

    --
    Tim Slattery
     
    Tim Slattery, Oct 17, 2006
    #4
  5. hrpreet

    hrpreet Guest

    Hi All,

    This is required since in case of updation need , i need to show the
    file text box prepopulated, but this doesnot happen, not allowed.

    Thanks

    Tim Slattery wrote:
    > Randy Webb <> wrote:
    >
    > >You get that error message because you can't programatically set the
    > >value of a file input element. It's a security violation.

    >
    > He's not trying to. He's retrieving the value of the <input
    > type="file"...> and assigning that to an <input type="text"...>
    > element.
    >
    > Why he needs to do that, I don't understand. The "file" element
    > includes a text box that gets set to the name of the file selected. It
    > seems that would show the exact same thing that he's trying to show in
    > his "text" box.
    >
    > --
    > Tim Slattery
    >
     
    hrpreet, Oct 19, 2006
    #5
  6. hrpreet

    Evertjan. Guest

    hrpreet wrote on 19 okt 2006 in comp.lang.javascript:
    > Tim Slattery wrote:
    >> Randy Webb <> wrote:
    >>
    >> >You get that error message because you can't programatically set the
    >> >value of a file input element. It's a security violation.

    >>
    >> He's not trying to. He's retrieving the value of the <input
    >> type="file"...> and assigning that to an <input type="text"...>
    >> element.
    >>
    >> Why he needs to do that, I don't understand. The "file" element
    >> includes a text box that gets set to the name of the file selected. It
    >> seems that would show the exact same thing that he's trying to show in
    >> his "text" box.


    [Please do not toppost on usenet]

    > This is required since in case of updation need , i need to show the
    > file text box prepopulated, but this doesnot happen, not allowed.


    If you change "need" to "want" you are right.

    However, security is about not always getting what you want.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Oct 19, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Erwan
    Replies:
    0
    Views:
    2,273
    Erwan
    Apr 2, 2004
  2. Jim
    Replies:
    0
    Views:
    4,879
  3. Jay
    Replies:
    2
    Views:
    1,086
  4. Roberto
    Replies:
    3
    Views:
    310
  5. Ste
    Replies:
    41
    Views:
    810
    Thomas 'PointedEars' Lahn
    Aug 1, 2007
Loading...

Share This Page