Welcome to WebmasterWorld Guest from 3.229.122.166

Forum Moderators: open

Message Too Old, No Replies

JS and html table

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

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

New User

10+ Year Member

joined:Sept 15, 2003
posts:2
votes: 0


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
3:24 pm on Sept 15, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 28, 2003
posts:492
votes: 2


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]

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

Preferred Member

10+ Year Member

joined:Apr 28, 2003
posts:492
votes: 2


<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]

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 20, 2002
posts:889
votes: 0


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

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

New User

10+ Year Member

joined:Sept 15, 2003
posts:2
votes: 0


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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 0


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

Jordan

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members