473,560 Members | 3,037 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing selected DIV text

I've managed to get the text a user has selected on a page (in a DIV not
a TEXTAREA) but I don't understand DOM methods well enough to change it.
That it to replace the text with some other text.

I've tried using deleteContents but I couldn't get it to work. And my
experiments with insertNode worked only intermittently.

I've read the relevant sections of developer.mozil la.org but while I
understand what the methods are supposed to do I can't actually get them
to work. Is there some info of a basic nature that explains their usage?

Andrew Poulos
Mar 17 '06 #1
2 14649
[posted and mailed]

Andrew Poulos <ap*****@hotmai l.com> wrote in news:441a95be$0 $18520
$5*******@per-qv1-newsreader-01.iinet.net.au :
I've managed to get the text a user has selected on a page (in a DIV not a TEXTAREA) but I don't understand DOM methods well enough to change it. That it to replace the text with some other text.

I've tried using deleteContents but I couldn't get it to work. And my
experiments with insertNode worked only intermittently.

I've read the relevant sections of developer.mozil la.org but while I
understand what the methods are supposed to do I can't actually get them to work. Is there some info of a basic nature that explains their usage?
Andrew Poulos


<html>
<script>
function changeMe(divID) {
divEl = document.getEle mentById(divID) ;
if (divEl) {
divEl.innerHTML = "<strong>No w</strong> this is really cool!!!";
}
}
</script>
<body>
<div id="divMyConten ts">
blah blah blah<br>
<a href="javascrip t:changeMe('div MyContents')>Ch ange Me</a>
</div>
</body>
</html>
Mar 17 '06 #2


Andrew Poulos wrote:
I've managed to get the text a user has selected on a page (in a DIV not
a TEXTAREA) but I don't understand DOM methods well enough to change it.
That it to replace the text with some other text.

I've tried using deleteContents but I couldn't get it to work. And my
experiments with insertNode worked only intermittently.


There is not necessarily some text selected that is part of only a
single text node where it would be clear what replacing the the text
means. So the question is what you wanted to replace if there is e.g. a
selection
<p><strong>Kibo |logy</strong> <em>f</em>o|r all</p>
where | is meant to show the boundary points of the range that forms the
selection. The selection as a text (i.e. window.getSelec tion.toString() )
is 'logy fo' but you then need to decide what to do exactly when you
replace stuff.

If you want to have an example where text is replaced that is all inside
of a single text node then you can check out
<http://home.arcor.de/martin.honnen/mozillaBugs/domLevel2/test2006031702. html>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 17 '06 #3

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

Similar topics

2
11022
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic SFSB and, from there, to the database. On the front end, all cells appear as text fields. However, for certain cells, when the user clicks on...
2
4269
by: John Smith | last post by:
Hey folks, I've got a combobox (DropDown List) in a windows form application which is bound to a DataSet. It's value is set to a numeric ID. It's visible text is set to a date. I need to make it so that the first item shows the words "Most Recent" instead of the date. I've tried setting the SelectedItem, Text, and SelectedText of the...
7
2940
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and already formatted as "Shopping" ---Bold "for" -----Regular Now I want to underline whole text by preserving old style i.e. Bold and
4
19617
by: Robert Bravery | last post by:
HI all, In JS, how can I change the selected value of a dropdownlist(select options) I know the value of indexed value of the selected value before it is changed. Thanks Robert
4
1742
by: shankwheat | last post by:
I'm passing a string like 'Div3,Div4' to use as options in a selectbox but I need the text the user sees in the box different from the values. My code populates the values in the selectbox correctly but not the text. Thanks Desired end result: <select id="selectBox" multiple="multiple" size="4"> <option value="Div3">About the...
2
2010
by: Gary Dale | last post by:
I have a form with a pull-down list with six options, each of which has a value set. The value is the e-mail account name (without the domain) of a group while the displayed value is the full name of the group that will receive the e-mail. I pass this.form to a function to validate the other data before handing it off to a script to...
1
3026
by: technod | last post by:
Hi, I have constructed a clickable list of words which are added to a select box. I then have buttons to move the added elements up or down in the list. The code below seems to work fine for the first change (UP only) but after that the last element in the list disappears :( I have no idea why this is happening so could anyone offer a...
3
1576
by: Darkside12 | last post by:
Hi, I'm trying to build a dynamic query by form. The idea is that a user can select a table in the database via a combo box and this will then change all of the text box labels on the form to match the field headers for the selected table. It also hides any text boxes that are surplus to the number of fields of the selected table. The user...
4
7798
pradeepjain
by: pradeepjain | last post by:
i have a menu of 4 items.all text color is white. and when i click a menu link the other menu items text color should change to black! Is it possible to do with css or javascript help is needed for this !if any example is there this would help me a lot as i am not gud in javascript!
0
7841
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8066
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7596
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7920
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6191
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5458
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5175
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3605
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.