By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,568 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,568 IT Pros & Developers. It's quick & easy.

Change text on a page

P: n/a
Using JavaScript, can I tag a block of text and then change the text
appearing in that block?

I'm doing a type of calculator and I'd like to display the resulting
number in a <td> (or div or whatever works) on the page. I'd like to
avoid using a text form field for the output.

Thanks.

Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
VK
> I'm doing a type of calculator and I'd like to display the resulting
number in a <td> (or div or whatever works) on the page. I'd like to
avoid using a text form field for the output.


Works nearly everything. "Quick-n-durty" way is

....
<td id="Output">Old text</td>
....

var myText = "New text";
var myHTML = "<b>New text</b>";
var out = document.getElementById("Output");
out.innerText = myText;
/* or
out.innerHTML = myHTML; */

The same with div and any other HTML tag. Just give them an ID.
Jul 20 '05 #2

P: n/a
don't think innerHTML works with older netscapes though.
Stu

"VK" <sc**********@yahoo.com> wrote in message
news:3f***********************@news.freenet.de...
I'm doing a type of calculator and I'd like to display the resulting
number in a <td> (or div or whatever works) on the page. I'd like to
avoid using a text form field for the output.


Works nearly everything. "Quick-n-durty" way is

...
<td id="Output">Old text</td>
...

var myText = "New text";
var myHTML = "<b>New text</b>";
var out = document.getElementById("Output");
out.innerText = myText;
/* or
out.innerHTML = myHTML; */

The same with div and any other HTML tag. Just give them an ID.

Jul 20 '05 #3

P: n/a
Stuart Palmer hu kiteb:
don't think innerHTML works with older netscapes though.
Stu


How many hands do you need to count those people still using such
netscapes?
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #4

P: n/a
Jim Mc wrote:
Using JavaScript, can I tag a block of text and then change the text
appearing in that block?
Yes, if the DOM of the UA supports that.
I'm doing a type of calculator and I'd like to display the resulting
number in a <td> (or div or whatever works) on the page.
Use DOM methods to get a reference to the `td' element and use DOM
properties to change its content. You find plenty of postings in
the newsgroup about it, please always search/read before you post.
I'd like to avoid using a text form field for the output.


Why, using forms that is the most compatible way to accomplish that.
PointedEars
Jul 20 '05 #5

P: n/a
On Mon, 8 Dec 2003 17:34:07 +0900, "Fabian" <la****@hotmail.com> wrote:
Stuart Palmer hu kiteb:
don't think innerHTML works with older netscapes though.
Stu


How many hands do you need to count those people still using such
netscapes?


I still have about 3% Netscape 4 visitors to my site. Not worth putting
a lot of effort into making a beautiful page for them, but worth making
sure it degrades gracefully.

--
Stephen Poley
Jul 20 '05 #6

P: n/a
JRS: In article <bn********************************@4ax.com>, seen in
news:comp.lang.javascript, Jim Mc <ji****@zolx.com> posted at Sun, 7 Dec
2003 16:10:52 :-
Using JavaScript, can I tag a block of text and then change the text
appearing in that block?

I'm doing a type of calculator and I'd like to display the resulting
number in a <td> (or div or whatever works) on the page. I'd like to
avoid using a text form field for the output.


Before posting (or answering), one should read the newsgroup FAQ. That
one is answered in Sec 4.15, in a manner compatible with two main
classes of browser.

=

Draft <URL:http://www.merlyn.demon.co.uk/hols.htm> (27 kB) needs
checking in different browsers. It uses FAQ 4.15 to write into a Div.

Primarily, does the bottom button give a Table, and does changing the
top entry in the right hand column change the other entries accordingly?

Secondarily (BI & NA only), do the BI / NA Tables show correct results?

Thirdly, do the words make sense?

Fourthly, does anyone know about holidays *controlled* by the EU or at
EU HQ?

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.