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

how to format Javascript Math results in some (predictable) tabular form?

P: n/a
I am just now learning Javascript to make a web-friendly special
function calculator for non-techies.

I figured out how to do what I wanted in a spreadsheet.

Then by trial and error modifying examples on tutorial sites I got the
JS part figured out to do single calculations.

What I WANT to do is generate small tables of 'what-if' outputs for a
range of one input's variation.

It could be done just by hoping that output prints consistnetly but
that is taking a big chance.

My next thought was to >try< to build an HTML table with JS code for
the Math equations, but that doesn't seem possible.

I'm hoping that can be done maybe in steps by putting data into an
array first then somehow formatting it into a table, or maybe that's
the wrong way to go about it.

Thank you

Murray

Sep 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
mu*******************@yahoo.com wrote:
<snip>
What I WANT to do is generate small tables of 'what-if' outputs for a
range of one input's variation.

It could be done just by hoping that output prints consistnetly but
that is taking a big chance.

My next thought was to >try< to build an HTML table with JS code for
the Math equations, but that doesn't seem possible.

I'm hoping that can be done maybe in steps by putting data into an
array first then somehow formatting it into a table, or maybe that's
the wrong way to go about it.

Heres a working sample to consider against your needs.
<div id="theTable">

</div>
<script language="javascript1.2" type="text/javascript">
<!--
szT='<table border="1"><tr>'
szT+='<td id="A0">0</td><td id="B0">0</td><td id="C0">0</td>'
szT+='</tr><tr>'
szT+='<td id="A1">0</td><td id="B1">0</td><td id="C1">0</td>'
szT+='</tr></table>'
document.getElementById("theTable").innerHTML=szT
document.getElementById("A0").innerHTML=" That Help?"
-->
</script>
--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Sep 21 '05 #2

P: n/a
Thank you for the clue, Dr.

Punctuation...nails me everytime.

Murray

Sep 22 '05 #3

P: n/a
OK, Dr.,

there is something very basic & essential I am not understanding in
your example.

I experimented with changing the numbers after the td id's to see the
effect(s). This did change the numbers in the displayed table except
for A0 remained 'This help?'. Maybe it's supposed to.

What this looks like to me is that I approached this the wrong way,
because it seems all I did was display a table based on table data (as
in the most basic conventional way).

So I am still missing some understanding of how I get MY function to
write or 'pass' it's result to these td id's 'A0', etc.

Maybe I need to research what purpose "document.getElementById" serves.
I think my brain simply didn't process that part because I didn't know
what it did, and I went right to what looked 'safe' to experiment with,
the "apparent" data.

If document.getElement retrieves a value, what purpose did the numbers
you placed in the szT table statements serve? Initial values?

Thank you

Murray

Sep 22 '05 #4

P: n/a


mu*******************@yahoo.com wrote:
So I am still missing some understanding of how I get MY function to
write or 'pass' it's result to these td id's 'A0', etc.


The only purpose of "A0" etc is so
that you could have a coordinate system for your function to
select the individual cells with.

column "A" row "0"

yourCellName = (column + row) //**** "A0"
yourCellObject=document.getElementById(yourCellNam e )

Now that you have the Object that represents the cell element in the table
yourCellObject.innerHTML="whatever you want"

--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Sep 23 '05 #5

P: n/a
ASM
Dr Clue a écrit :

<script language="javascript1.2" type="text/javascript">
are you sure that 2 last lines of this script
are javascript 1.2 ?
szT='<table border="1"><tr>'
szT+='<td id="A0">0</td><td id="B0">0</td><td id="C0">0</td>'
szT+='</tr><tr>'
szT+='<td id="A1">0</td><td id="B1">0</td><td id="C1">0</td>'
szT+='</tr></table>'
document.getElementById("theTable").innerHTML=szT
document.getElementById("A0").innerHTML=" That Help?"
</script>


--
Stephane Moriaux et son [moins] vieux Mac
Sep 27 '05 #6

P: n/a
ASM wrote:
Dr Clue a écrit :
<script language="javascript1.2" type="text/javascript">

are you sure that 2 last lines of this script
are javascript 1.2 ?
szT='<table border="1"><tr>'
szT+='<td id="A0">0</td><td id="B0">0</td><td id="C0">0</td>'
szT+='</tr><tr>'
szT+='<td id="A1">0</td><td id="B1">0</td><td id="C1">0</td>'
szT+='</tr></table>'
document.getElementById("theTable").innerHTML=szT
document.getElementById("A0").innerHTML=" That Help?"
</script>


As to that particular language attribute , I simply type it out
of pure habit, as at one time it mattered.

In general , I don't think of javascript in terms of versions
but rather the absence and presence of objects and the mappings
of same. If I need an object and it is not there , I'll fake it.

I have an old-school version of the above code in my demos
that does the same thing w/o getElementById too.

--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Sep 27 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.