Jump to content

Searching For Strings In Text


aotearoa

Recommended Posts

I am trying to make a little script that allows a user to search for blocks of text within strings.  The user enters data into form fields and he or she can enter text into another form field (needle) to search the data fields (haystack).  When the search string matches something in the data fields the associated data fields are highlighted in a yellow background color.

 

Right now the search string is acting funny. When I enter a search string I get no highlighting unless if the first character(s) of the search string are the same as the first character(s) for the items.  For instance, If I search for the text "at" in the word "bat" I will not get any yellow highlighting. But I would get highlighting for "bat" if I search for "ba."  How would I change the code so that any data field is highlighted if the search string exists anywhere in the text for the data field?

 

Also, I figured out how to stop the form fields from being yellow if they and the search field are empty/NULL, but I did this part in another file (as an IF statement) and can't seem to get it to work in the other file.  How would I make it do the highlighting if and only if there is a search string in the search field (i. e. only highlighting when the search field is not NULL/empty).

 

The code from my 2 files is here...: http://pastie.org/1095526 , http://pastie.org/1095528

 

Thanks very much to anyone who can help me.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.