javascript loads specific page else ALERT

Im REALLY new at Javascript - been browsing these forums and reading up like crazy for ony two weeks, to try and learn enough for a project i'm working on.

THE QUESTION IS:

I want the user to be able to type in a number (eg: abc_123) that will launch a popup containing the page (eg: abc_123.htm). I've managed to get this right by adapting a password script(where password= pagename.htm). That was quite easy.

BUT now i need to do this: IF they type in a filename that doesnt exist, it must either load a page saying "the number you have entered..." or cause an ALERT to popup. I've read that one can customise error pages and upload them to the server, but then that page would appear for ANY other error on the site too.

Is there a way to do this? I would guess I need to use an IF (else) statement. Is there any way javascript could check to see if the page exists (then load it), otherwise popup a custom page or ALERT

There are going to be about 15 code numbers that the user could type in (and these will be changing from week to week). I was hoping there was a way i could use javascript to check the files in the directory and act accordingly.

I guess one way would be to put the 15 numbers in an array (?), and use javascript to check that way, but that means i'll have to keep changing the array every few days - which i'm trying to avoid. Could i place that array in an exernal .js file to make it easier to update?

Comments

: Hi!: : Im REALLY new at Javascript - been browsing these forums and reading up like crazy for ony two weeks, to try and learn enough for a project i'm working on.: : THE QUESTION IS:: : I want the user to be able to type in a number (eg: abc_123) that will launch a popup containing the page (eg: abc_123.htm). I've managed to get this right by adapting a password script(where password= pagename.htm). That was quite easy.: : BUT now i need to do this: IF they type in a filename that doesnt exist, it must either load a page saying "the number you have entered..." or cause an ALERT to popup. I've read that one can customise error pages and upload them to the server, but then that page would appear for ANY other error on the site too.: : Is there a way to do this? I would guess I need to use an IF (else) statement. Is there any way javascript could check to see if the page exists (then load it), otherwise popup a custom page or ALERT: : There are going to be about 15 code numbers that the user could type in (and these will be changing from week to week). I was hoping there was a way i could use javascript to check the files in the directory and act accordingly.: : I guess one way would be to put the 15 numbers in an array (?), and use javascript to check that way, but that means i'll have to keep changing the array every few days - which i'm trying to avoid. Could i place that array in an exernal .js file to make it easier to update?: : But ideally i'd prefer not to have to update every few days...: : : I've inserted my code below if needed.: : Any help would be MUCH appreciated!: : (AN excited-about-javascript newbie): : : : ------- CODE: ----------------: : : : : : : function(doThis) : {: refvar = document.form1.refnum.value;: }: : : : : : : : refnum: : : : : : : : function findpage(refUrl): {: refvar = document.form1.refnum.value;: refUrl = (refvar + ".htm"): var mypopup2=window.open((refUrl),"win4",'width=300,height=400');: mypopup2.focus();: }: : : : : GET MY PAGE: : : : : Here is a trick to check if a page exists. It might only work for IE 5+, but at least it's something:[code] var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.load(refUrl); if (xmlDoc.parseError.errorCode == -2146697210) { alert("Page does not exist!"); } else { alert("Page exists. Continueing to load it"); }[/code]This loads the page as a XML-file into the XML-parser. It will always return an errorCode, since your page isn't valid XML. The code above is returned if the page isn't found.

However, it's the easiest way to do it. The only other ways that I can think of (apart from the one you're trying to avoid) would be to put the pages in a seperate folder and set the 404 page for that, if you can, or to read the HTML of the page, and if it matches your 404 set it to a different page: