/    Sign up×
Community /Pin to ProfileBookmark

Adding a ‘Go!’ button to an input box in order to jump to a page

Hi everyone,

Two years have passed since my last attempt of creating a website, and here I am again?
Basically what I need is quite easy to understand, but I have no clue in how to make it. I’m just -almost- sure that I need my page to be saved as PHP.

Alright, I have about 100 pages in my website, and rather than creating a dropdown list with all 100 pages, I’d like to create an input box with a ‘Go!’ button, so that when the user writes ABC and clicks on the button, he ‘domain.com/ABCpage.htm’ opens up. In short, the button should understand what the user have typed, find the proper link according to the text and open the page.

Please note that every keyword will have to be associated to a link, and if the keyword is not in the list, an error page should come out.

Any clue on how to do it? Thanks for any help!:eek:

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@yomamacableguyJul 26.2008 — you can use javascript to make this. i'm not sure how to do it in php.

<script type="text/javascript">

function searchlinks() {

var linkarray = new Array();

linkarray[0] = searchtext1

linkarray[1] = url1

linkarray[2] = searchtext2

linkarray[3] = url2

var searchtext = document.getElementById('search')

//This returns 0, 2, 4, 6, etc. - the search texts

for (i=0; i<linkarray.length; i+2) {

if (searchtext.indexOf(linkarray[i]) > -1) {

document.location = linkarray[i+1]

}

}

</script>





then, in the body of the document:

<input type="text" id="search"> <input type="button" onClick="searchlinks();">





that should work. i haven't tested it out - i thought it up as i was typing ^_^
Copy linkTweet thisAlerts:
@paokunauthorJul 27.2008 — Hi!

Thanks for the quick reply.

I've tried it, I had to add a } at the end but still unfortunately the button text is not visible, and when clicking on it this is the error that comes out from Firebug:

[CODE]searchtext.indexOf is not a function
[Break on this error] if (searchtext.indexOf(linkarray[i]) > -1) {[/CODE]


Do you know how to fix it??
Copy linkTweet thisAlerts:
@yomamacableguyJul 27.2008 — <script type="text/javascript">

function searchlinks() {

var linkarray = new Array();

linkarray[0] = searchtext1

linkarray[1] = url1

linkarray[2] = searchtext2

linkarray[3] = url2

var searchtextcontainer = document.getElementById('search')

var searchtext = searchtextcontainer.value

//This returns 0, 2, 4, 6, etc. - the search texts

for (i=0; i<linkarray.length; i+2) {

var linktext = linkarray[i]

if (searchtext.indexOf(linktext) > -1) {

document.location = linkarray[i+1]

}

}

}

</script>



hmmm... not sure why it didn't work. try this one (sorry for the missing bracket. as i said, i made that script up as i was typing XD)



oh and to make text display in the button, assign it a value:

<input type="button" value="Go!">



post here or pm me if that doesn't work ^_^



EDIT: wow, i feel so stupid. XD i forgot to store the text box's value in a variable. it's fixed now. XD
Copy linkTweet thisAlerts:
@paokunauthorJul 27.2008 — Thnks for the reply, but same error. The 'Go!' text appears, though?
Copy linkTweet thisAlerts:
@yomamacableguyJul 27.2008 — <script type="text/javascript">

function searchlinks() {

var linkarray = new Array();

linkarray[0] = searchtext1

linkarray[1] = url1

linkarray[2] = searchtext2

linkarray[3] = url2

var searchtextcontainer = document.getElementById('search')

var searchtext = searchtextcontainer.value

//This returns 0, 2, 4, 6, etc. - the search texts

for(i=0; i<linkarray.length; i+2) {

var linktext = linkarray[i]

if(searchtext.indexOf(linktext) > -1) {

document.location = linkarray[i+1]

} else {

alert('Incorrect Search!')

}

}

}

</script>



if that doesn't work, then i'm not sure what's wrong with it. you can use this though. it takes longer to set up, but it should get the job done.



<script type="text/javascript">



function searchlinks() {

var container = document.getElementById('search')

if(container=="search term 1") {

document.location = "url 1"

}else if(container=="search term 2") {

document.location = "url 2"

} else {

alert('Incorrect Search!!')

}

}

</script>



that came out of my head in two seconds, so there may be an error in my typing somewhere in there.
Copy linkTweet thisAlerts:
@paokunauthorJul 27.2008 — hmm the first one crashes the browser because the error message keeps popping up, instead the second one looks better, but it always says that the search is incorrect no matter what string I put in.

When deleting one '=' from [B]if(container=="search term 1") {[/B], making it [B]if(container="search term 1") {[/B], then no matter what you put in the input box but it always goes to the first url.

Better than before! Thanks for trying to work it out!
Copy linkTweet thisAlerts:
@yomamacableguyJul 27.2008 — oh my god!!! (no offense) I FORGOT TO STORE THE VALUE AGAIN!!!!! use this: *bangs head against the wall until dizzy*

<script type="text/javascript">

function searchlinks() {

var container = document.getElementById('search').value

if(container=="search term 1") {

document.location = "url 1"

}else if(container=="search term 2") {

document.location = "url 2"

} else {

alert('Incorrect Search!!')

}

}

</script>
Copy linkTweet thisAlerts:
@paokunauthorJul 27.2008 — and.. it works like a charm!!!?

Thank you really very much!

It's 4.10 am, now I can sleep happy?

Have a nice Sunday!
Copy linkTweet thisAlerts:
@yomamacableguyJul 27.2008 — any time. sorry it took so long XD you too.
×

Success!

Help @paokun 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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