/    Sign up×
Community /Pin to ProfileBookmark

Help with going to a found page

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 “[url]http://www.pedsforparents.com/articles/1234.html”[/url] There would have to be an error message if the page couldn’t be found.

Thanks for helping out a beginner.

Rich

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Jul 06.2005 — If you want to do this in Javascript, you need to store an array of valid pages:

<i>
</i>&lt;script type="text/javascript"&gt;

<i> </i>var validUrls=Array("1234","4567","5678","6789");

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

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

&lt;/script&gt;
&lt;form method="get" onsubmit="return loadPage(this)"&gt;
&lt;input type="text" name="pageRef" size="10"&gt;
&lt;input type="submit" name="Go to Page"&gt;
&lt;/form&gt;
Copy linkTweet thisAlerts:
@A1ien51Jul 06.2005 — 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
×

Success!

Help @rsagall spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...