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 8 of 8

Thread: which button?

  1. #1
    New to the CF scene
    Join Date
    May 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile which button?

    Hi All, I am really new to this so if someone can help thanks

    I have put together some code to be prompted to open a file. Only I can not figure out how to hook into the event triggered by pressing the 'OK' or 'Cancel' buttons in the dialog.

    Also can someone explain the line:

    onclick='document.all.hiddenFileName.click()'


    THANKS Jess

    --------

    <SCRIPT type="text/javascript">
    function fnUpdatetext(e)
    {
    alert("filename " + e);
    fnFilenname();
    }

    </script

    <FORM name="dummy" >
    <INPUT type="file" class="file" style="display: none" name="hiddenFileName" onchange='fnUpdatetext(this.value)'>
    <input type="button" value="Cancel" onclick='alert("cancel button pressed")'>
    <input type="text" style="visibility:hidden" name="Filename" >

    <input type="button" name="openFile" width=40 height=18 style="position:absolute;top:0px;left:600px" value="open file"
    onclick='document.all.hiddenFileName.click()'
    >
    </FORM>

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,518
    Thanks
    3
    Thanked 506 Times in 493 Posts
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    </
    head>

    <
    body>
    <
    SCRIPT type="text/javascript">
    function 
    fnUpdatetext(e)
    {
     if (
    document.getElementById('Filename').style.visibility=='hidden'){
      
    document.getElementById('Filename').style.visibility='visible';
      
    document.getElementById('openFile').value='cancel';
      
    document.getElementById('hiddenFileName').style.display='block';
     }
     else {
      
    document.getElementById('Filename').style.visibility='hidden';
      
    document.getElementById('openFile').value='open file';
      
    document.getElementById('hiddenFileName').style.display='none';
     }
    }

    function 
    fnUpdatetext2(v){
     
    document.getElementById('Filename').value=v;
    }

    </script>

    <FORM name="dummy" >
    <INPUT type="file" class="file" style="display:none" id="hiddenFileName" name="hiddenFileName" onchange='fnUpdatetext2(this.value)'>
    <input id="Filename" type=text style="visibility:hidden;" name="Filename" >

    <input type="button" id="openFile" name="openFile" width=40 height=18
     style="position:absolute;top:0px;left:600px" value="open file"
    onclick='fnUpdatetext()'
    >
    </FORM>
    </body>

    </html> 

  • #3
    New to the CF scene
    Join Date
    May 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    No, that's not what I want.

    The code below invokes a file open dialog, but it does not work correctly every time. It only works correctly when the user chooses a different file over the one displayed and presses OK.


    Do the following:
    Press 'file Open' Select a file, press OK - file name displayed (close it)
    press 'file open' press 'OK' to currently selected file - no display
    It's only triggered on OK and onChange event occuring

    Obviously it would be much better to hook into the return value from dialog. How do you do this?

    <SCRIPT type="text/javascript">
    function fnUpdatetext(e)
    {
    alert("filename " + e);
    }

    </script

    <FORM name="dummy" >
    <INPUT type="file" class="file" style="display: none" name="hiddenFileName" onchange='fnUpdatetext(this.value)'>

    <input type="text" style="visibility:hidden" name="Filename" >

    <input type="button" name="openFile" width=40 height=18 style="position:absolute;top:0px;left:600px" value="open file"
    onclick='document.all.hiddenFileName.click()'
    >
    </FORM>

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    onchange was not triggered because there is no change in the value of the input file. That's the expected behavior. Do you want onchange to be always invoked even if there is no change in the value?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New to the CF scene
    Join Date
    May 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I understand the event and this event would work if I forced the filename value to be NULL before invoking the dialog. But that is nasty and it changes the expected behaviour of the dialog. All I want to know is:

    How do I find out what message was thrown in the File Open Dialog to close it?

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by jessie_buns
    How do I find out what message was thrown in the File Open Dialog to close it?
    There's no way to know what button is clicked.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    New to the CF scene
    Join Date
    May 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    There's no way to know what button is clicked.

    I don't think so.

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by jessie_buns
    I don't think so.
    So how?
    AFAIK, there's no way to know what the File Dialog returns in the same way the confirm() method does. That is because, you're not directly calling a function to open the File Dialog. It is internally invoked by a built-in File input element which the programmer has no control of.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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