473,394 Members | 2,071 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,394 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 9781
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.