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

    Question Question about telling a script in which folder to look! Please help!

    Hello,

    I have this code:

    Code:
    <script type="text/javascript">
    
    function PasswordLogin()
    {
        var filename = document.formlogin.trackingnr.value.toUpperCase() + ".html";
        var http = window.XMLHttpRequest
            ? new XMLHttpRequest()
            : new ActiveXObject('MSXML2.XMLHTTP.3.0'); 
    
        if (!http)
        {
            window.location = filename;
            return false;
        }   
    
        http.open('GET', filename, true);
        http.onreadystatechange = function()
        {
            if (http.readyState == 4)
            {
                if (http.status == 200)
                {
                    window.location = filename;
                }
                else
                {
                    alert('Votre Numero est errone. Merci de reessayer!');
                    return false;
                }
            }
        }
        http.send(null);   
        return false;
    }
    
    
                              </script>

    It works well, but I don't know what to modify in order for it to search the html file in another folder (deeper). For example, now it only searches the in the folder where the script is (which is in a html page), and I would like it to look for the document in a given folder let's say "transactions" which is down one level. What should I modify? Can you help please? Thanks

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Looks like this is where it's being set:

    Code:
    var filename = document.formlogin.trackingnr.value.toUpperCase() + ".html";
    My guess on a change would be something like this...

    Code:
    var filename = "transactions/" + document.formlogin.trackingnr.value.toUpperCase() + ".html";
    Might not work, especially witohut having a chance to see exactly what the trackingnr.value is, but eh... with a bit of tweaking (if needed), I'm sure you'll make it do what it should.

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple folders

    Works perfect for one folder, what if i want to look in two separate folders:

    var filename = "transactions/" + document.formlogin.trackingnr.value + ".html";

    How to add another folder ?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,166
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    You mean look for it in two possible locations?

    Only way to do that is to try the one location and, if not found, look in the other one.

    You could do that by looking at the http.status: If it was 404 (file not found) instead of 200, then you would have to tell your code to look in the other folder.

    Somewhat more complex code.

    Why would you not know what folder a file is in???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have one folder "transaction" and another one called "stock"

    The search works perfect for transaction and i want to add folder stock. The script must look in both folders.

    Is possible ?

  • #6
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Its OK, if not fount in folder Transaction then look in the other one. how do i do that ?

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Code:
    function PasswordLogin(folder)
    {
        var filename = folder+"/" + document.formlogin.trackingnr.value.toUpperCase() + ".html";
        // ...
    then,
    Code:
    PasswordLogin("transactions");
    PasswordLogin("stock");
    you probably want to remove the alert since one will fail.

    you can make an additional progress monitor to throw the alert up if both fail:

    Code:
    function doPageSearch(){
      doPageSearch.tries=2; // how may folders to search?
      PasswordLogin("transactions");
      PasswordLogin("stock");
    }
    then change
    Code:
    else
                {
                    alert('Votre Numero est errone. Merci de reessayer!');
                    return false;
                }
    to
    Code:
    else
                {
     
                    if(! --doPageSearch.tries)  alert('Votre Numero est errone. Merci de reessayer!');
                    return false;
                }
    Last edited by rnd me; 11-14-2012 at 11:07 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

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