Javascript search engine

Hey Guys,
I have got a javascript code to the internet and i wanted to change it a bit.
I want the same search result if i search for ABC, aBc, ABc or abC.
I am getting result only if i type abc in the search box. Any one to help please?
Here is the code:

var item = new Array();

// "La page","Son adresse","","Titre de la page","Mot clés","Description de la page"

c = 0;
item[c] = new Array("Imea RDC", "", "", "imea, imea, aru, djedi, matthias, ecole, banque, en, ligne, scolaire", "L'institut Mgr Emile Aiti est une institution d'enseignement scolaire qui prone l'education de qualite avant tout le reste...");
item[c] = new Array(" Voir plus sur la CECA 20 Aru ville ", "", "", "ceca, 20, aru, ville, eglise", "La CECA 20 Aru ville est une eglise de la 20e communaute evangelique en Afrique au Congo, situe a l'exctreme ...");
item[c] = new Array("", "", "", "", "");

page = "<html><head><title>Résultat de la recherche</title></head><body bgcolor='white'><center><table border=0 cellspacing=10 width=90%><p>Faire une nouvelle recherche</p>";

function search(frm) {
  win ="", "_self", "scrollbars");
  txt = frm.srchval.value.split(" ");
  fnd = new Array();
  total = 0;
  for (i = 0; i < item.length; i++) {
    fnd[i] = 0;
    order = new Array(0, 4, 2, 3);
    for (j = 0; j < order.length; j++)
      for (k = 0; k < txt.length; k++)
        if (item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "")
          fnd[i] += (j + 1);
  for (i = 0; i < fnd.length; i++) {
    n = 0;
    w = -1;
    for (j = 0; j < fnd.length; j++)
      if (fnd[j] > n) {
        n = fnd[j];
        w = j;
    if (w > -1) total += show(w, win, n);
    fnd[w] = 0;
  win.document.write("</table><br>Pages trouvé(s): " + total + "<br></body></html>");

function show(which, wind, num) {
  link = item[which][1] + item[which][0];
  line = "<tr><td><a href='" + link + "'>" + item[which][2] + "</a> <br>Identifiant: RO/" + num + "<br>";
  line += item[which][4] + "<br>" + link + "</td></tr>";
  return 1;

Welcome to the Free Code Camp forum.

I am not 100% sure what your code is doing, but is the following line where you “search”? If not, you will need to give more details about what you mean.

if (item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "")

I would assume you need to be checking the indexOf txt[k].toLowerCase(). This would allow you to match without regards to case.

Also, I formatted your code (using proper indentation) to make it more readable. Also, I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


It is a search engine in javascript

I am blocked one week ago…

Hey dear,
I have tried many times, nothing is happening…
I know this “if (item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != “”)” is the code that should allow me to do that, but i do not know what is wrong…
Please help me…

That script is good for what i wanna do. I would like it also to display the search results to the same page where the search box is. I want the script to prevent loading a new tab …But the main for now, it is that lower and upper case issue…

Did you try converting the above the lowercase within the if statement?

No. But how to convert it please? Help me…

You have already written code that converts strings to lowercase, so you should be able to do this yourself. If not, then you might need a refresher in basic JavaScript. You can check out our Basic JavaScript curriculum here.