Click to See Complete Forum and Search --> : Help with going to a found page


rsagall
07-06-2005, 07:21 AM
I am just a beginner with JavaScript. What I need is a script that will allow the visitor to type in a four digit code - e.g. 1234. Then I want to open a page with a URL that would be “http://www.pedsforparents.com/articles/1234.html” There would have to be an error message if the page couldn’t be found.

Thanks for helping out a beginner.

Rich

crh3675
07-06-2005, 07:48 AM
If you want to do this in Javascript, you need to store an array of valid pages:


<script type="text/javascript">

var validUrls=Array("1234","4567","5678","6789");

function loadPage(f){
var page=f.pageRef.value;
var gotoPage="error.html";

for(i=0;i<validUrls.length;i++){
if(page==validUrls[i]){
gotoPage=page+".html";
break;
}
}
document.location.replace(gotoPage);
return false;
}

</script>
<form method="get" onsubmit="return loadPage(this)">
<input type="text" name="pageRef" size="10">
<input type="submit" name="Go to Page">
</form>

A1ien51
07-06-2005, 08:51 AM
You can use AJAX to determine if the page exists. You can easily change the example on my blog to work the way you want.

http://radio.javaranch.com/pascarello/2005/06/24/1119626686861.html

Eric