JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2061
Number of posts: 5164

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
javascript search bar help Posted by nawsh on 13 Apr 2004 at 1:49 PM
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.
Report
Re: javascript search bar help Posted by zibadian on 13 Apr 2004 at 9:24 PM
: 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:
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');
}

Report
Re: javascript search bar help Posted by Weirdofreak on 14 Apr 2004 at 12:34 AM
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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.