bench
02-05-2003, 01:50 PM
I am trying to allow somebody to search a webpage for certain words. I have succeeded in searching the document for a specific word in the text range, but am having trouble search for the word again if it appears later throughout the document. Here's the code below:
<html>
<head>
<title>New Page 1</title>
<script>
function performSearch(){
var textRange = document.body.createTextRange();
if (textRange.findText("ben")){
textRange.select();
if (textRange.findText("ben")){
textRange.select();
}
}
}
</script>
</head>
<body>
<p><input type="button" value="Button" name="B3" onclick="performSearch();"></p>
<p>dfgdfgdfgbendxfgfgdbenfsdfdben</p>
</body>
</html>
The above code only highlights the first "ben" found in the document, but I would like it to highlight the second "ben" in the document.
Any help with this matter would be most appreciated.
Many Thanks in advanced,
Ben Chivers
<html>
<head>
<title>New Page 1</title>
<script>
function performSearch(){
var textRange = document.body.createTextRange();
if (textRange.findText("ben")){
textRange.select();
if (textRange.findText("ben")){
textRange.select();
}
}
}
</script>
</head>
<body>
<p><input type="button" value="Button" name="B3" onclick="performSearch();"></p>
<p>dfgdfgdfgbendxfgfgdbenfsdfdben</p>
</body>
</html>
The above code only highlights the first "ben" found in the document, but I would like it to highlight the second "ben" in the document.
Any help with this matter would be most appreciated.
Many Thanks in advanced,
Ben Chivers