Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keyword Search on Just One Page

Status
Not open for further replies.

cmaynard

MIS
Nov 12, 2003
9
0
0
US
Is there a script that I can use so that people can do a keyword search on just the page they are on?
 
I use this JavaScript on a page I have..

Put this in the HEAD SECTION....

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var NS4 = (document.layers);
var IE4 = (document.all);

var win = this;
var n = 0;

function findInPage(str) {
var txt, i, found;
if (str == "")
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0) alert(str + " was not found on this page.");
}
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}
if (found) {
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
else
alert(str + " was not found on this page.");
}
}
return false;
}
// End -->
</script>

Put this where you want the search form

<form name=search onSubmit="return findInPage(this.string.value);">
<font color="#072B6D">Search for Name:</font>
<input name=string type=text size=25 onChange="n = 0;">
<input name=submit type=submit value="Search" style="font-size: 11; font-family: Arial">&nbsp;<hr size="1">
</form>

Hope this helps

DBigger
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top