markgt
04-10-2004, 12:46 PM
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:
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. I've inserted my code below if needed.
Any help would be MUCH appreciated!
(AN excited-about-javascript newbie)
------- CODE: ----------------
<html>
<head>
<script ="javascript">
function(doThis)
{
refvar = document.form1.refnum.value;
}
</script>
</head>
<body>
<form name="form1">
refnum:
<input type="text" id="refnum" name="refnum" value=""><BR>
</form>
<script type="text/javascript">
function findpage(refUrl)
{
refvar = document.form1.refnum.value;
refUrl = (refvar + ".htm")
var mypopup2=window.open((refUrl),"win4",'width=300,height=400');
mypopup2.focus();
}
</script>
<BR>
<BR>
<a href="#" onClick="findpage(); return false">GET MY PAGE</a>
</body>
</html>
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:
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. I've inserted my code below if needed.
Any help would be MUCH appreciated!
(AN excited-about-javascript newbie)
------- CODE: ----------------
<html>
<head>
<script ="javascript">
function(doThis)
{
refvar = document.form1.refnum.value;
}
</script>
</head>
<body>
<form name="form1">
refnum:
<input type="text" id="refnum" name="refnum" value=""><BR>
</form>
<script type="text/javascript">
function findpage(refUrl)
{
refvar = document.form1.refnum.value;
refUrl = (refvar + ".htm")
var mypopup2=window.open((refUrl),"win4",'width=300,height=400');
mypopup2.focus();
}
</script>
<BR>
<BR>
<a href="#" onClick="findpage(); return false">GET MY PAGE</a>
</body>
</html>