Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-07-2009, 12:19 AM   PM User | #1
DeeDee2010
New to the CF scene

 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
DeeDee2010 is an unknown quantity at this point
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
DeeDee2010 is offline   Reply With Quote
Old 03-07-2009, 02:17 AM   PM User | #2
Eldarrion
Regular Coder

 
Join Date: Feb 2009
Location: Wheeling, IL
Posts: 358
Thanks: 5
Thanked 62 Times in 60 Posts
Eldarrion is on a distinguished road
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.
Eldarrion is offline   Reply With Quote
Old 11-14-2012, 12:55 AM   PM User | #3
hvalentine6
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
hvalentine6 is an unknown quantity at this point
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 ?
hvalentine6 is offline   Reply With Quote
Old 11-14-2012, 01:20 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is online now   Reply With Quote
Old 11-14-2012, 02:11 AM   PM User | #5
hvalentine6
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
hvalentine6 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 11-14-2012, 02:16 AM   PM User | #6
hvalentine6
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
hvalentine6 is an unknown quantity at this point
Its OK, if not fount in folder Transaction then look in the other one. how do i do that ?
hvalentine6 is offline   Reply With Quote
Old 11-14-2012, 11:03 AM   PM User | #7
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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;
            }
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 11-14-2012 at 11:07 AM..
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:31 AM.


Advertisement
Log in to turn off these ads.