Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Resolved HTML search box to search on a page
    Have you got the solution while drafting your question?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,472
    Thanks
    0
    Thanked 634 Times in 624 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #5
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,332
    Thanks
    5
    Thanked 363 Times in 360 Posts
    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

  • #6
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #7
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,332
    Thanks
    5
    Thanked 363 Times in 360 Posts
    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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •