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

Create a textarea where some text is in a different color

I want to do this:

<textarea>
perl
<font color="FF0000">
$thing_to_get=17;
</font>
More Perl code using $thing_to_get
</textarea>

But the above doesn't work, of course.

The idea is that I'm giving the users a bunch of text where they might
want to edit the red parts. Then I'll have a javascript button to
select all. A user modifies the variable, clicks on the "select all"
button, and then pastes the code into a Unix window (then presses
Ctrl-D to run the script).

I don't want a WYSIWYG editor, I don't even need the user to be able to
decide which text to make red. All I want is to be able to set a piece
of the textarea to be red in the firstplace.

Reading here & in various javascript script archives, it seems like I
need to do fancy IE/Mozilla-specific contentEditable stuff. Is there a
simpler way to handle it?

Thanks,

-Amir Karger

Jul 23 '05 #1
1 4954
fox


am***********@yahoo.com wrote:
I want to do this:

<textarea>
perl
<font color="FF0000">
$thing_to_get=17;
</font>
More Perl code using $thing_to_get
</textarea>

But the above doesn't work, of course.

The idea is that I'm giving the users a bunch of text where they might
want to edit the red parts. Then I'll have a javascript button to
select all. A user modifies the variable, clicks on the "select all"
button, and then pastes the code into a Unix window (then presses
Ctrl-D to run the script).

I don't want a WYSIWYG editor, I don't even need the user to be able to
decide which text to make red. All I want is to be able to set a piece
of the textarea to be red in the firstplace.

Reading here & in various javascript script archives, it seems like I
need to do fancy IE/Mozilla-specific contentEditable stuff. Is there a
simpler way to handle it?


One way (among many similar) is to simply:

This is <span id=sectionname class=hilite onclick =
"changeText(this)">editable</span> content.

script support:

function
changeText(e)
{
if(s = prompt("change text to:", e.innerHTML))
e.innerHTML = s;

// you do not want to allow an empty string
// or the item "disappears" (nothing to click on)
}

use styles to dress up the hilited text any way you want...e.g.:

..hilite {
cursor: pointer;
color: red;
}

just make sure each editable section has a unique id attribute and this
will fit just about anywhere (except inside textareas and other form
elements)... will work with any server-side support.

BTW, this makes the resultant document printable [ use @print to change
hilite to color: black (or whatever)].

[tested ie and firefox/mozilla]

fox...
Jul 23 '05 #2

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

Similar topics

2
by: Manuel Reimer | last post by:
Hello, I want to add some text in front of an object. I want to use the ":before" tag for that. I've tried to do this like the following: object, embed + *:before { content:"test";...
6
by: TomT | last post by:
Hi, I've created a form that has a 3 fields. 2 textboxes (username & password) 1 TextArea (notes) I have linked this to an access DB. This is working well, the user enters thier Username...
8
by: Orloff | last post by:
Hi, on most (all?) browsers, when you put the pointer on a <a href="..." title="popup text">this is a link</a> without clicking on the link, there is a popup caption with the "popup text". I...
0
by: Tony Johansson | last post by:
Hello! Below is a small program using the adaptor pattern. We have four classes these are: PegAdapter, RoundPeg, SquarePeg and a class TestPegs acting like a client In class PegAdapter has...
10
by: Wayne Wengert | last post by:
Is there a way for ASP.NET/VB codebehind to get the contents of a plain old <textarea> element? I added an id='myname' to the <textarea> tag but VSNET complains that it is undefined? Wayne
7
by: Ron | last post by:
Hello, I have 4 classes that use 4 DTS packages on 4 different tables. So I have Dim cls1 As New clsDTS1, cls2 As New clsDTS2 Dim cls3 As New clsDTS3, cls4 As New clsDTS4 Each class has a...
2
by: mariomueller | last post by:
Hello everybody, I am looking for a method to get the text on the left and the right side if a user selects some text in a textarea. Regards Mario
5
by: ad | last post by:
I want to show the background color of a row in a gridview to different color when the value of a column is greater than 100. How can I do?
3
by: UJ | last post by:
Is there a way to have items in a drop down list where certain items are a different color? How about having items that are strikethrough? TIA - Jeff.
4
by: barronmo | last post by:
I'm a beginner searching for an easy way to print the contents of a text control. So far I've come up with the following(difficulties): 1) using wxPython -convert to HTML and then print (I...
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: 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
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.