Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-15-2012, 05:20 AM   PM User | #1
habeeb506
New to the CF scene

 
Join Date: Dec 2011
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
habeeb506 is an unknown quantity at this point
Smile HTML search box to search on a page

Hi Team,

I needs some corrections in the following code.

The code is to search content on a page...

<SCRIPT language=JavaScript>
var NS4 = (document.layers);
var IE4 = (document.all);
var win = window;
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("Not found.");
}
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("Sorry, we couldn't find.Try again");
}
}
return false;
}
</SCRIPT>

<FORM name=search onsubmit="return findInPage(this.string.value);">
<P align=center><FONT size=3>
<INPUT
style="BORDER-RIGHT: #666666 1px solid; BORDER-TOP: #666666 1px solid; FONT-SIZE: 8pt; BORDER-LEFT: #666666 1px solid; BORDER-BOTTOM: #666666 1px solid"
onchange="n = 0;" size=16 name=string></FONT><BR><INPUT style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid; FONT-SIZE: 8pt; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #ffffff 1px solid; FONT-FAMILY: Tahoma; BACKGROUND-COLOR: #aaaaaa" type=submit value=Search in page ><center><font size=2pt;><font family=Times New Roman;><b>

<font face="Tahoma"><a target="_blank" href="http://www.htmlfreecodes.com/"><span style="font-size: 8pt; text-decoration: none">HTML Free Code</span></a></font>








But this code functions similar to CTRL + F as we use to search.

I need the text box to accept space first then the text typed in it so that it will work in a unique way to find meaning full words.

Thanks
habeeb506 is offline   Reply With Quote
Old 02-15-2012, 05:23 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
Resolved HTML search box to search on a page
Have you got the solution while drafting your question?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 02-15-2012, 07:52 AM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by habeeb506 View Post
I needs some corrections in the following code.
That code is for IE4 and Netscape 4 and no one uses those browsers any more so the first thing to do is to delete all the code you currently have.

The second thing to do is to get a page search script that works with modern browsers such as the one at http://javascript.about.com/library/blufind.htm
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 02-15-2012, 10:39 AM   PM User | #4
habeeb506
New to the CF scene

 
Join Date: Dec 2011
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
habeeb506 is an unknown quantity at this point
Thank you for your response.

I know that the code is for old browsers but we have restrictions.

By looking at the above posted code can you make some changes so that once we press search button It should concatinate sapce and the letter in the text box to search ?

It will be really helpfull for me according to the current requirement

Thank you
habeeb506 is offline   Reply With Quote
Old 02-15-2012, 02:09 PM   PM User | #5
teedoff
Senior Coder

 
Join Date: Aug 2010
Location: High Point, NC
Posts: 3,325
Thanks: 5
Thanked 363 Times in 360 Posts
teedoff is on a distinguished road
I have to ask why you'd want a js search form? Poeple DO sometimes turn off js in their browsers, therefore your search function would not work. Just a thought.
__________________
Teed
teedoff is offline   Reply With Quote
Old 02-17-2012, 03:59 AM   PM User | #6
habeeb506
New to the CF scene

 
Join Date: Dec 2011
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
habeeb506 is an unknown quantity at this point
Ok then is there an alternative way without java script to meet the above requirement ??

1. Search Box for all 748 pages

2. It should search any word on the page with a beginning letter (Not in the middle of a word)

Please let me know so that I can start working and deploying it.

Thank you
habeeb506 is offline   Reply With Quote
Old 02-17-2012, 02:04 PM   PM User | #7
teedoff
Senior Coder

 
Join Date: Aug 2010
Location: High Point, NC
Posts: 3,325
Thanks: 5
Thanked 363 Times in 360 Posts
teedoff is on a distinguished road
Quote:
Originally Posted by habeeb506 View Post
Ok then is there an alternative way without java script to meet the above requirement ??

1. Search Box for all 748 pages

2. It should search any word on the page with a beginning letter (Not in the middle of a word)

Please let me know so that I can start working and deploying it.

Thank you
If you dont know how to code your own, ZoomIndex has a very nice tool. You download the software, make a few initial decisions like which language to us(php, asp.net, coldfusion, and others), then it will index all your pages and create the function for you. Its free for up to 50 pages, but only $99 for sites up to 200,000 pages.

There are of course many others like this, but I can speak for this one since I have used it myself.
__________________
Teed
teedoff is offline   Reply With Quote
Reply

Bookmarks

Tags
html, page, search box, text

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:35 AM.


Advertisement
Log in to turn off these ads.