Forum Moderators: open

Message Too Old, No Replies

JS and html table

How to take the values of tables cell to JS...

         

canlidinc

2:52 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



Hi everyone,
I have a big table with a lot of number in its cells in html. I want to make calculations with these numbers in JS and print the values on screen. I tried to give a unique name to cells by writing;
<td id="cell_1_2">

but I dont know How I can get the value of this cell?
Or another option, to hold my data in array, but in that situation I was planning to delete my numbers in html and make script write to proper cells, and couldnt handle it?
Any idea, comment? Thank you
-Ali

dougmcc1

3:24 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



Welcome to WebmasterWorld canlidinc.

I would use a form instead of a table, and inputs instead of td's.

[edited by: dougmcc1 at 3:37 pm (utc) on Sep. 15, 2003]

dougmcc1

3:25 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function CalculateValues()
{
var x = window.document.FormName.InputName1.value
var y = window.document.FormName.InputName2.value
var z = x - y;
window.document.FormName.Result.value=z;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="FormName">
<INPUT TYPE="TEXT" VALUE="0" SIZE="10" NAME="InputName1"><BR>
<INPUT TYPE="TEXT" VALUE="0" SIZE="10" NAME="InputName2"><BR>
<INPUT TYPE="BUTTON" VALUE="Submit" onClick="CalculateValues()">
&nbsp;
<INPUT TYPE="RESET" VALUE="Reset" onClick="doClear()"><BR>
Result: <INPUT TYPE="TEXT" VALUE="0" NAME="Result" SIZE="20">
</FORM>
</BODY>
</HTML>

[edited by: dougmcc1 at 3:35 pm (utc) on Sep. 15, 2003]

Iguana

3:32 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should be able to (in IE) get document.all("cell_1_2").innerText

Possibly easier is to

tbl = document.all("datatable")

then cycle through the tbl.rows collection and the tbl.rows(1).cells collection and pick out the .innerText properties

canlidinc

7:30 am on Sep 16, 2003 (gmt 0)

10+ Year Member



Hi again,
First of all thank you for your kind (and fast) interest. Iguana's offer seems more close to my prb then dougmcc1's. Because my data is read only and since it is a thermodynamic table i have to publish it in table format. Playing with my data issue seems solved at this moment :)
I want to show the results in a Message Box using
alert();
function. Is there an option to format the text using html tags? I tried to use
<br>
but it didnt work. Or can I show them in a new pop-up window?If yes, How will I forward my data from my original page to new page? Thanks Again...

-Ali
love peace respect

MonkeeSage

8:05 am on Sep 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



var val = document.getElementById("cell_1_2").innerHTML;
val = val.replace(/<br>/g, "\n");
alert(val);

Jordan