English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi, I'm a javascript newbie (but html capable). can anyone please help me with this javascript problem?

This is the page.
http://cmpt165.cs.sfu.ca/~jca49/cmpt165/test2.html

If you look at the source code, there is a little bit of javascript in there. Right now, if the "Click Me" button is clicked, it leads a new page with the words "Hello World!".

However, what I want to do is when the button is clicked, the words "Hello World!" should be written to the current document. Specifically, written to the

with id="txt". In other words, I want it so that when a button is clicked, some new text is added to a specific location on the current page.

Is there anyway to do this? So far I don't know if document.write() can achieve this.

Thank you!

2007-03-16 10:56:44 · 3 answers · asked by cherri_pwincesu 1 in Computers & Internet Programming & Design

3 answers

math guy was close! but that solution only works in internet explorer! Had he attended a real university or studied comp sci or knew how to program cross platform.... he'd have known it has to be

document .getElementById("txt") .innerHTML = "Hello World!";

2007-03-16 12:57:04 · answer #1 · answered by jake cigar™ is retired 7 · 0 0

You are close. The document.write method changes the internals of the body tag to your parameter string.

You need to specify the object that you want the value to be displayed within. Use the document.all method to get the paragraph tag that you want the string in, then use the innerHTML method to paste your value in that tag.



PS. If you would have gone to Capilano College instead of SFU, you would know this ;)

2007-03-16 11:12:34 · answer #2 · answered by Math Guy 4 · 0 1

That's called AJAX

2007-03-16 11:12:57 · answer #3 · answered by Carlos V 2 · 0 2

fedest.com, questions and answers