473,395 Members | 1,456 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,395 software developers and data experts.

Change text on a page

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
6 3097
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: google | last post by:
I have a HTML file that contains an iframe. The HTML file is served by one server. The iframe contains a link to a completely different server. My question is, can any action in the iframe (such...
4
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an...
3
by: Ken McCrory | last post by:
I have a web form page (.aspx) with 95 label controls that I now need to be text boxes. Is there an easy way to change those to what I want using something like a find and replace or am I stuck...
4
by: sid derra | last post by:
hi i am trying to change the value of a text field on my page dynamically, every time an iframe loads. #========== the code where the text field is looks like this: <form...
3
by: John Smith | last post by:
I'm looking into this peace of code: protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (DropDownList)sender; TableCell cell = list.Parent as...
2
by: John Smith | last post by:
Will this line of the code: item.Cells.Text = "Some text..."; change only DataGrid visual value or it will also change value in the DataSource? How can I change value in DataSource? ...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
4
by: Ross Presser | last post by:
I'm feeling very stupid about this ... pdf2html (http://pdf2html.sourceforge.net) is an app that reads a PDF and can generate HTML or XML; in my case I'm using the XML. The PDF I'm working with...
5
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I change the text in the url/location bar?...
6
by: K Viltersten | last post by:
I have the following button: <asp:LinkButton id="Btn" runat="server" text="Click"> </asp:LinkButton> I have added an action listener in the javascript where I change the text on it:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.