473,378 Members | 1,571 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,378 software developers and data experts.

Highlighting part of the text in a text box

Hi all,

I've been struggling with this for days. How can I use javascript to
high light a part of the text in a textbox or a textarea?

OR

if the user highlights a part of the text in a textbox or a textarea,
how can I say which part of the text is highlighted? (ie: at what
character the highlight starts and at what character the highlight
ends).

thanks in advance.

Oct 12 '05 #1
3 4166
Aria wrote:
if the user highlights a part of the text in a textbox or a textarea,
how can I say which part of the text is highlighted? (ie: at what
character the highlight starts and at what character the highlight
ends).


function sel(o) {
if (o.selectionStart) {
return o.value.substring(o.selectionStart,o.selectionEnd) ;
} else {
return document.selection.createRange().duplicate().text;
}
}

....
<input type="text" onmouseup="alert(sel(this))" />
JW

Oct 12 '05 #2
thanks. Is o.selectionStart and o.selectionEnd the code to use for
netscape?

Oct 12 '05 #3
Aria wrote:
thanks. Is o.selectionStart and o.selectionEnd the code to use for
netscape?


Yes.
JW

Oct 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Edo van der Zouwen | last post by:
I have the following problem. On a website there's a (simple) feedback form. This is used also by Polish visitors who (of course) type Polish text using special characters. However, when I...
5
by: nboutelier | last post by:
Scenario: you enter "foo bar" into a text field... Is it possible through javascript to select/highlight just "foo"? formObject.select() selects all. I need to select only part of the string....
1
by: Suresh Tri | last post by:
Hi, I was trying to overload concat operator ||(text,text) such a way that it behaves like Oracle. i.e. I want 'abc' || null to return 'abc' instead of null. I know that it is not the expected ...
2
by: Johann Robette | last post by:
Hi, I'm trying to call the array_to_string function like this : SELECT array_to_string(array, '~^~') --> it comes directly from the doc. I get this error msg : ERROR: parser: parse error at...
4
by: David Garamond | last post by:
What is "text + text" supposed to do right now? It doesn't seem very useful to me. What about making "text + text" as an equivalent for "text || text"? Most strongly-typed programming languages do...
1
by: Gap | last post by:
Hello all, I want to create a page with an image and when the cursor is moving over the image (e.g. over text on the image the text is highlighted or changes color or something similar. So that...
1
by: Eric | last post by:
Hi, I have a detailsview which shows large text. What i want is to show only the beginning of the text in normal mode and the full text in edit mode. Here the code: Thanks Eric ...
4
by: stitch121103 | last post by:
I'm working on asomething that has an image map with multiple hotspots. When the hotspot is clicked, I need it to highlight a particular row in the table that gives information about the person that...
1
by: hariharan2105 | last post by:
I have an single column document. How would I render a small part of text (say, figure caption) in two columns. I use Apache FOP. Any suggestions?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.