/    Sign up×
Community /Pin to ProfileBookmark

Goto page input in text box

I need a simple javascript that will open an html page input as text in a form.
enter page number.
if user enters 1
onclick href=page1.html
if user enters 2
onclick href=page2.html
var could be name or alphanumeric
if user enters shakespear
onclick href=shakespear.html

< input type = “text”
onclick= if “Text=1” href=page1.html etc.. for all pages. if invalid page is entered then no action user stays on current page.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@rnd_meOct 29.2008 — [CODE]

<a id="a1">Type a page to jump to: </a>
<input id="text1" />
<input type="button" onclick="build()" value="build">

<script>

var pages = { //define all possible pages here:
1: "page1.html",
2: "page2.html",
shakespear: "shakespear.html"
};

function build(){
var key = document.getElementById("text1").value;
var newPage = pages[key];
var a = document.getElementById("a1");
if(newPage){
a.href=newPage;
a.innerHTML = key;
} else {
a.href="javascript: alert('please enter a valid page.')"
a.innerHTML = "Type a page to jump to:";
}

}

</script>

[/CODE]
Copy linkTweet thisAlerts:
@djkoolauthorOct 30.2008 — thanks rnd me
×

Success!

Help @djkool 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.6,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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