CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Question about telling a script in which folder to look! Please help! (http://www.codingforums.com/showthread.php?t=160588)

DeeDee2010 03-07-2009 12:19 AM

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

Eldarrion 03-07-2009 02:17 AM

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.

hvalentine6 11-14-2012 12:55 AM

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 ?

Old Pedant 11-14-2012 01:20 AM

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???

hvalentine6 11-14-2012 02:11 AM

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 ?

hvalentine6 11-14-2012 02:16 AM

Its OK, if not fount in folder Transaction then look in the other one. how do i do that ?

rnd me 11-14-2012 11:03 AM

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;
            }



All times are GMT +1. The time now is 02:04 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.