PDA

View Full Version : Javascript Search...Case sensitive


bacterozoid
10-20-2002, 11:35 PM
Well, I have a nifty search on my site, and I have one problem with it. It is case sensitive. Whatever you enter into the search bar has to be exactly how I have it in the base search file for it to come up. Here is the link:

http://www21.brinkster.com/jonshtmlhelp

The search bar on the sidebar on the left is what I am referring to. It loads from an external .js file, the source is this:


document.writeln('<br><br><form name=\"form\" method=get
action=\"javascript:void(0)\" onSubmit=\"return false\"> <p
align=\"center\"><input type=text name=srchval size=\"10\"
style=\"color: #000000\; background-color: #B4B4B4\; font-
family: arial\; font-size: 8pt\; border: 1 solid #808080\"
onChange=\"javascript:this.value=this.value.toLowerCase()
\;\"><br> <input type=submit value=\"Search\" style=\"color:
#000000\; font-family: arial\; font-size: 8pt\; background-color:
#C0C0C0\; border: 1 solid #808080\" onclick=\"search(form)
\;\"></p></form>');


(That is the script, which refers to another JS file further up in the document.)

I have integrated a code which automatically changes any text inside the search field to lower case, but the user can not submit using ENTER, which is really annoying. Any way I can either make it non-case sensetive or have the script change to lowercase on submit instead of onChange? I have worked with this before, but never got any further.

Off-topic, I do plan to get that search to appear right on the page, not in the pop-up window. Any comments on the *Incomplete* site are welcome as well as help.

Thanks a bunch!

ConfusedOfLife
10-20-2002, 11:48 PM
I would have tried this :



document.writeln('<br><br><form name=\"form\" method=get
action=\"java script:void(0)\" onSubmit=\" return search(this.srchval.value.toLwerCase())\"> <p
align=\"center\"><input type=text name=srchval size=\"10\"
style=\"color: #000000\; background-color: #B4B4B4\; font-
family: arial\; font-size: 8pt\; border: 1 solid #808080\"
\"><br> <input type=submit value=\"Search\" style=\"color:
#000000\; font-family: arial\; font-size: 8pt\; background-color:
#C0C0C0\; border: 1 solid #808080\"
\"></p></form>');




And I would have defined a class instead of adding all these styles to my script. I tried to run your code but it didn't work, I think you didn't put the whole code here, huh?

Edit : I can delete the contents of your news box, isn't it great?!

bacterozoid
10-20-2002, 11:51 PM
Clever, but what does it do. Does it just read any value as lower case?

bacterozoid
10-21-2002, 12:35 AM
Hehe, yes, you can edit the contents of my news box. That is, until I go back and stick the 'readonly' tag on there.

And no, that's not the entire code. The rest is somewhere else, lol. You can find it if you really look hard ;)

As for defining classes, ack, I don't know how to do that, lol.

bacterozoid
10-21-2002, 01:21 AM
Er...it doesn't work, lol.

glenngv
10-21-2002, 03:01 AM
Originally posted by ConfusedOfLife
I would have tried this :



document.writeln('<br><br><form name=\"form\" method=get
action=\"java script:void(0)\" onSubmit=\" return search(this.srchval.value.toLwerCase())\"> <p
align=\"center\"><input type=text name=srchval size=\"10\"
style=\"color: #000000\; background-color: #B4B4B4\; font-
family: arial\; font-size: 8pt\; border: 1 solid #808080\"
\"><br> <input type=submit value=\"Search\" style=\"color:
#000000\; font-family: arial\; font-size: 8pt\; background-color:
#C0C0C0\; border: 1 solid #808080\"
\"></p></form>');




typo?

onSubmit=\" return search(this.srchval.value.toLowerCase())\"

bacterozoid
10-21-2002, 03:36 AM
Lol, yes, it was a typo...but it's messed up now, lol. *Sigh* Know of any other search scripts that don't have these problems?

ConfusedOfLife
10-22-2002, 02:22 PM
Bacterozoid, I think it's better that you remove the document.write and copy and paste the whole code into a new document, see if your code works in normal HTML and then you put the double quotes, coz then if you see any problem, you could be sure that it's a syntax error with your double qutoes and not anything else.

PS: Try to write your scripts yourself and FIX them whenever you get a bug, don't go for others works, It's all in your mind, remember?

bacterozoid
10-22-2002, 09:40 PM
Well in reply to your first point: On my site I want that menu to appear on all my pages, and after I get so many pages, it gets annoying to have to go to every page and change the code. I don't want to use an iFrame, nor frames, and I don't think my host supports SSI, and if it did I don't know how to use it. What I have there is the product of many antagonizing situations. As for just the search script though, I stuck it on the end of my menu script source for the sake of getting it in the same place on all my pages.

As for writing my own scripts, eh...I'm way ahead of myself in many areas. I haven't even began to understand the full capabilities of javascript, and can only write simple codes. I work with larger scripts because they are nice and I can generally tell what they are telling the document. I can customize them to an extent, as well. When I do that if I mess up the script I go back and look for the error, then fix it.