473,765 Members | 1,968 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 14655
[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
11061
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 the cell, the text field turns into a drop-down field (i.e. Select object), defaulting to the value...
2
4279
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 list box to "Most Recent", when the SelectedIndex changes to 0, but nothing happens.
7
2972
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
19626
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
1749
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 Company</option> <option value="Div1">Ratings</option>
2
2020
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 actually do the mailing. The mailer script looks at all of the form's fields and sends their names and...
1
3039
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 solution or a better method of doing the above task? Thanks in advance <html>
3
1586
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 can then add their search criteria into the text boxes and search the selected table. To achieve...
4
7806
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
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8831
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5275
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.