Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

javascript search bar help

nawshnawsh Posts: 4Member
Hello I was wondering if anyone could tell me where i could get some code to put a search bar on my website nothing fancy, just something that will search my main directory for files that i need any help would be most appreciated.

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hello I was wondering if anyone could tell me where i could get some code to put a search bar on my website nothing fancy, just something that will search my main directory for files that i need any help would be most appreciated.
    :
    Javascript cannot open and read external files, so you'll have to create a database of keywords for each of those files in your script. Searching through those words can be done using the indexOf() method of each keyword entry. Here is an untested sample code:
    [code]
    var keyWords = new Array;
    keyWords[0] = 'www.google.com|search,websearch,find';
    keyWords[1] = 'www.programmersheaven.com|javascript,delphi,programming,pascal';

    function performSearch(searchstr)
    {
    for (i=0; i < keyWords.length; i++)
    {
    if (keyWords[i].indexOf(searchstr) != -1)
    {
    location.href = keyWords[i].split('|')[0]; // go to the new location
    }
    }
    alert('No matches found');
    }
    [/code]
  • WeirdofreakWeirdofreak Posts: 439Member
    A Javascript one wouldn't work at all well, although that would probably be the best way to do one.

    The best way would be to use a google search box. I can't find a link to get it on the site, but you could emulate it (vaguely) but having a form that googlesearches for the words they put in the box, but appends a site:yoursite.
Sign In or Register to comment.