Click to See Complete Forum and Search --> : Plz Help!!! I need script for word matching box!!!
FiLaN
07-20-2003, 09:25 PM
I really need the script for a word matching box urgently!
It works just like a search engine but search the words within a definition page that I wrote.
The user can enter their word and the box can match the word itself within the definition page.
That's all I need. Sure it's not hard for u guys.
Plz help me!!
Not sure exactly what your set up is, so it's hard to give exact help, but you should look into regexp (http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/regexp.html#1193136).
FiLaN
07-20-2003, 09:43 PM
In my site, there is a page with all the definitions of special terms. At the top of this page I want a "word matching box", which is like the one in those search engine.
The box is able to allow user to enter the word they dunno and will find that word within the definition page.
That's it. Hope U guys can help, THX!!
This is not prefect, but it should get you going. Try searching for test:
<html>
<head>
<script type="text/javascript">
function searchPage(frm) {
contents = document.getElementsByTagName("body")[0].innerHTML;
str = frm.searchbox.value;
re = new RegExp(str, "i")
if (re.test(contents)) {
alert (str+" was found");
}
else {
alert (str+" was not found");
}
return false;
}
</script>
</head>
<body>
<form name="searchform" onsubmit="return searchPage(this);">
<input type="text" name="searchbox">
<input type="submit" value="Search">
</form>
test
</body>
</html>
brendandonhue
07-20-2003, 10:16 PM
Or just set an anchor to each word like this
<a name="word1"></a>
Definition1
<a name="word2"></>
Definition 2
And use a form/function like this
<script language="javascript">
function jump()
{
var word = document.search.word.value;
var url = document.location + "#" + word;
document.location = url;
}
</script>
<form name="search" action="jump()">
<input type="text" name="word">
<input type="submit" value="search">
</form>
FiLaN
07-20-2003, 10:58 PM
Really Thx for the scripts, but sorry that they are not very suitable for my page.... :(
Will it be easier that I separate the page into 2 pages??
1st page : the "search box"
2nd page: the page with all the words
So user can enter the word into the search box and the 2nd page will pop up with the matched word highlighted <thus sth like the search word function in MS Word>
Hope this will be better to find a suitable script.... Plz DUN STOP Helping me about this!! I really need this!!
Jumbawumba
07-20-2003, 11:02 PM
lol
Exuro
07-21-2003, 01:19 AM
Okay, that took me awhile but I think I have a nice solution for you. Just play around with the code in the text file I attached... There's a comment in there that talks about changing <b> to whatever tag you have before every one of your glossary terms, this is so that it doesn't jump to anywhere that word pops up in the document. If you don't want to bother with that just take out the whole "<b>" + part. Anyway, hope that helps you!