Results 1 to 2 of 2

Thread: Case-Sensitive Search

  1. #1
    Join Date
    Apr 2007

    Unhappy Case-Sensitive Search

    Hi Gang!

    I'm learning some JavaScript iun a class and I have a search engine running a search on a JS file with 40 listings. The files I have are from a very old book, I bet some of you know it...the "JavaScript Application Cookbook." I'm trying to modify the JS and HTML pages to make the search be case sensitive. I have inserted a checkbox which is suppose to change the value of the function which controls if the search should be case-sensitive or not. So far, I have not been able to get it to work. It continues to come back as being case INsensitive. I could use some help if you please to get this to work.

    I have tried several things recommended to me by my instructor, but nothing he has done has worked. We have enabled the console logger of Firebug to show the values for our functions and variables.

    Here is some of the JS code which controls the search:
    var CASE_SENSITIVE = false; // ***** ***** controls case-sensitive search across functions
    var HTTP_RE = /\|[Hh][Tt][Tt][Pp]/; // ** regular expression object, for '|http' searching
    var CASE = false;
    var NOCASE = true;
    // Determine the type of search, and make
    // sure the user has entered something
    function validate(entry, isSensitive) { // ** nocase added, to enable/disable case-sensitive search
      consoleLog("validate(\n\n=>" + entry + "\n\n" + isSensitive + " called."); // *****
      CASE_SENSITIVE = (isSensitive == "false" ? CASE : NOCASE);
    here is the HTML file which contains the checkbox
    HTML Code:
    <TITLE>Search Nav Page</TITLE>
    <SCRIPT LANGUAGE="JavaScript1.1" SRC="records.js"></SCRIPT>
    <SCRIPT LANGUAGE="JavaScript1.1" SRC="nav2.js"></SCRIPT> 
      <FONT FACE="Arial">
      <B>Client-Side Search Engine</B>
      <FORM NAME="search" onSubmit="validate(document.forms[0].query.value,NOCASE); return false;">
      <INPUT TYPE=TEXT NAME="query" SIZE="33">
      <INPUT TYPE="checkbox" name="case" id="case" value="1"><LABEL FOR="case">
      Case-Sensitive search</LABEL>
      <B><A HREF="main.html" TARGET="main">Help</A></B>
    Any help you can provide to get this to work will be acknowledged.


  2. #2
    Join Date
    Dec 2002
    Pleasanton, CA
    Not sure exactly what you are doing, but...

    var http_re = /http/; will match http (lower-case only)
    var http_re = /http/i; will match both HTTP and http (note the trailing 'i')

    Hope that helps

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
HTML5 Development Center

Recent Articles