473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

highlighting a searched word it text area

Hi,

I want to highlight a searched word in the text area using javascript .
Jul 10 '08 #1
3 9778
hsriat
1,654 Expert 1GB
It might be something like:
Expand|Select|Wrap|Line Numbers
  1. /*JavaScript Code*/
  2. function highlight(word) {
  3.     var txt = document.getElementById('textDiv');
  4.     txt.innreHTML = txt.innerHTML.replace(' ' + word + ' ', ' <span class="highlight">' + word + '</span> ');
  5. }
  6. //where textDiv is the div which contains the text.
Expand|Select|Wrap|Line Numbers
  1. /*CSS code*/
  2. span.highlight {
  3.     background-color:yellow;
  4. }
See if this works.
Jul 10 '08 #2
Markus
6,050 Expert 4TB
Do you mean highlight some text that's in a text area? Or highlight the text given through a text area?
Jul 10 '08 #3
rnd me
427 Expert 256MB
this will find and highlight the first one:
Expand|Select|Wrap|Line Numbers
  1. function showMatch(TXT, phrase){ 
  2.     var t= TXT.value;
  3.     var lp = t.split(phrase)[0].length;
  4.     TXT.selectionStart = lp
  5.     TXT.selectionEnd = lp + String(phrase).length;    
  6. }
TXT is an object: the textarea

phrase is the string (or regexp) to find.
Jul 11 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Adelson Anton | last post by:
Hi all, Ok, this is what I want to do: When you press, say Ctrl+K ( it doesn't matter which event), I want the , say, second word in the document to be highlighted. Anyone has any idea how...
1
by: Ms Yaqian Fang | last post by:
Hello, I want to highlight the clicked area on an image by placing another image on it. But it replaced the whole image, not the clicked area. My code is as following, can anyone please help me?...
0
by: Chris Crook | last post by:
Hey Everyone, Currently I have a table with an Article field which, you guessed it, contains an entire article. In a form, you type in a search word. I created a function that returns the...
4
by: Bob hotmail.com> | last post by:
Everyone I have been spending weeks looking on the web for a good tutorial on how to use regular expressions and other methods to satisfy my craving for learning how to do FAST c-style syntax...
2
by: Johnny | last post by:
Sorry I posted this post earlier but got the name and subject the wrong way round (new to this!) so it perhaps didn't look right Sorry for that. But please please answer if you know anything about...
0
by: Brian Scott | last post by:
I am currently trying to control the syntax highlighting of a richtextbox control whilst the user types. At the moment I have implemented a thread which calls the richTextBox.Invoke on a method...
7
by: JohnSmith90 | last post by:
I want to highlight the entire cell data for all rows of a particular column in a data grid. I do not want to fill the back ground color of the cell. How to do that in a data grid? <span...
7
by: Leif902 | last post by:
After much searching of google, the closest I can find is highlighting search terms... however, this is not what I wanted to do. Does anyone know how to parse through a specific element (lets say...
0
by: athirukk | last post by:
Hi, I am doing Office (Word) programming in .Net with Microsoft.Office.Interop.Word. My C# code highlights the a text range in a Word document with the following snippet. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.