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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile how to validate the browse file button ???

    I've written the code as in jsp :
    <html:file property="browsefile" value="" onkeyup="keyp()" />
    and in the script i wrote as:
    function keyp() {
    alert("Please select the file through the browse button ! ");
    alert(document.AddDeSelNumForm.browsefile.value);
    document.AddDeSelNumForm.browsefile.value='';
    document.AddDeSelNumForm.browsefile.focus();
    }


    what i want is , not allowing the user to input the file manually. he must have browse the file through the browse button and shouldn't write it manually.
    Here in this i've to use the struts one html file option because i'm using this function for other.
    Here what is happening is, when i press any key it is popping up the message but after click on OK, the value which i entered is remains there only eventhough i'm using :document.AddDeSelNumForm.browsefile.value='';
    but the strange think is that when i'm alerting that particular value it is showing the the value of the browse text which u have entered the text. I'm really confused why it not clearing the field. Please help me out in this reagard or suggestions are always welcome.
    Please suggest me how to do or please fix this bug.

    in advance thanks a lot.....

  • #2
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    not entirly sure here but cant you just disable the field and the browse button still works?
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)

  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how to disable the text field of browse button so that browse button still works. I don't know how to disable such thing. Could anyone tell me how to achieve this problem.
    Please help me out in this regard....
    in advance thanks....

  • #4
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have one question, whats the difference between them clicking the button and manually typing in the path? Why do you need the person to click the browse button?
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)

  • #5
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because i'm retreiving the path of the directive and doing the bulk insert in the database. Two operation has to be done one is Replace and one is Append. So, in this case if the user enter through manually then it might be the case that the user entered the wrong or some other path. So, i don't want the user to use the manually script.
    There are also some other logic to do this, it is going to the action class(Struts) and there the manipulation is occuring . If the user input on the jsp page then it gets the javascript error. SO, i want to put the text field of the browse button disable and only through the button the user can access or some other logic is there then please forward me.....
    I'm in confused state, please help me out.....
    Also, tell me in my code where the logic overflows (PLEASE)....

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You can try using
    Code:
    onkeypress="this.blur()"
    inside of the file input. This in theory won't allow users to type in the box. It will move their cursor out of the file input. I'm not sure if this will work on the web but you could try it.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I really don't know much about the subject but I read a post recently that said security for the <input type="file"> element is more strict than most inputs. I don't know if that applies to writing to the value or not.

    Here is the post.

    Quote Originally Posted by _Aerospace_Eng_ View Post
    Don't add the quotes, do what Bill suggested. The reason its likely not working is because the file type input has a higher security than the other input boxes. I've tried this before. On a internet level the file input doesn't seem to allow you to get its value. Try it locally on your desktop of your computer it probably will work. Put some alerts into the function to see if its even being called.
    I suspect the reason you can't change it is because you could change it to some file on the users machine and they could accidently upload a sensitive file.

    Here is some code similar to yours that I wrote to text it. I had the same problem you had.

    Code:
    <html>
      <head>
        <title>Junque</title>
        <script type="text/javascript">
          function doIt(id) {
            var o = document.getElementById(id);
            var s = o.value;
            o.value = "";
    
            var adiv = document.getElementById(id + "div");
            adiv.innerHTML = id + " = '" + s + "'";
          }
        </script>
      </head>
      <body>
        <div>
          Type something in each file then click the buttons to try and delete it<br/>
          These two buttons use the same function<br />
          <button onclick="doIt('text');">Get and Delete Text</button>
          <input type="text" name="text" id="text" />
          <br/>
          <button onclick="doIt('file');">Get and Delete File</button>
          <input type="file" name="file" id="file" />
          <div id="textdiv"> </div>
          <div id="filediv"> </div>
        </div>
      </body>
    </html>
    david_kw

  • #8
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    again i'm getting the problem. First thing is that when i'm using with :
    onkeypress="this.blur()", it is working fine but when i copy and paste it is throwing error again. Can't it possible to disable the text field of browse button.
    And Second thing is that i can't use the ids with the struts framework. I've written the code above , please have a look over it and please tell what should i do now.....
    Any other thing or way , can i modelate my code...
    Last edited by navgreat; 02-08-2007 at 07:54 AM. Reason: Error occuring again !!

  • #9
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    You can try using
    Code:
    onkeypress="this.blur()"
    inside of the file input. This in theory won't allow users to type in the box. It will move their cursor out of the file input. I'm not sure if this will work on the web but you could try it.
    Have you tried the following
    Code:
    onkeypress="this.value = '';"
    that would then null the field every time the key is pressed rather than loosing focus, what is the error message you are receiving? I am guessing its a security error one correct?
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)


  •  

    Posting Permissions

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