473,396 Members | 2,158 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,396 software developers and data experts.

Writing HTML to a webpage using document.getElementById('results').childNodes[0].nodeValue

Hi,

I am trying to update part of a webpage using javascript. The bit that gets
updated will have a variable number of links written to it.

I have done this successfully by rewriting the whole page but this seems
like overkill (and a maintenance problem too potentially).

I thought about defining the area to be updated using a div. Something like
this:

<div id="results">Results will go here</div>

with the javascript doing something like:

var src = "blah blah blah";
document.getElementById('results').childNodes[0].nodeValue = src;

This works if src is just text. If it is HTML, say:

var src="<p><a href=\"some_file.html\">Some file</a></p>";

Then inside the div instead of getting a link to some_file.html I get the
raw HTML.

Is there either a way round this problem or a much better way of doing it in
the first place?

Thanks

Deryck
Jul 23 '05 #1
2 3712


Deryck wrote:

I thought about defining the area to be updated using a div. Something like
this:

<div id="results">Results will go here</div>

with the javascript doing something like:

var src = "blah blah blah";
document.getElementById('results').childNodes[0].nodeValue = src;

This works if src is just text. If it is HTML, say:

var src="<p><a href=\"some_file.html\">Some file</a></p>";

Then inside the div instead of getting a link to some_file.html I get the
raw HTML.

Is there either a way round this problem or a much better way of doing it in
the first place?


Learn the DOM e.g.
var p = document.createElement('p');
var link = document.createElement('a');
a.href = 'some_file.html';
p.appendChild(a);

var resultsDiv = document.getElementById('results');
while (resultsDiv.hasChildNodes()) {
resultsDiv.removeChild(resultsDiv.lastChild);
}

resultsDiv.appendChild(p);

or help yourself with innerHTML

resultsDiv.innerHTML = '<p><a ...>...<\/a><\/p>';

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:41***********************@newsread4.arcor-online.net...


Learn the DOM e.g.
<Useful code snipped for brevity>


Thanks Martin...I appreciate your quick response.

Deryck
Jul 23 '05 #3

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

Similar topics

2
by: Stan | last post by:
Hello all, I'm looking for some hints as to how to use the results of a query in another query. I assume I'm 'thinking' wrong in how to solve this, so I'm hoping someone can clobber me and send...
7
by: adam | last post by:
i'm working on a portion of a CMS that allows content-admins to browse a product list, and add individual products into the taxonomy by clicking checkboxes next to categories they might belong in....
2
by: sharma | last post by:
Hi, I Have a page which will take authentication from a diffrent page from a difrent website. My program needs to call a page like this from php page lets say:...
16
by: lisa.engblom | last post by:
I have two semi related questions... First, I am trying to output a list of strings to a csv file using the csv module. The output file separates each letter of the string with a comma and then...
1
by: John Raines | last post by:
Hello- I am trying to parse HTML results which look like this: <html> <body> <span class=aaa>this is a test</span><span class=bbb>testing again</span><span class=aaa>test number 3</span>...
1
by: philiprodley | last post by:
Dear All-- I have three text boxes on a form. Two of the text boxes come from 1 table (same record). The third field is calculated from the other two. I wish to store the result held in the...
2
by: tvance929 | last post by:
Hey guys, Can someone turn me onto a tutorial or at least give me some begining advice how to accomplish the following: I am making an Loan Payment calculator. I want to give the user the...
0
by: techjohnny | last post by:
I would like to take this output and write it to a file, thankyou.html. Any help would be great. thanks, --tj if($gen_thank == "on" ) { $form_process .="?>\n\n\n<!-- This is the content...
3
by: Schwabs | last post by:
I am attempting to gather interest data and post it into one window. I am able to get the to write properly using the Standard I/O, however, when I attempt to display the data using...
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: 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...
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...
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
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,...

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.