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

undefined NaN, surely not!!

Hello all

I am having a small problem wih a javascript, could anyone help me
please

1. first of all

this code requires a form f01 and textarea t01

<form name ="f01">
<textarea name="t01" rows="80" cols="50">
</textarea></form>

2. the javascript is as follows:
----------------------

function point(x,y,z){
this.x = x;
this.y = y;
this.z = z;
}
function mkPoints(){
tmp01 = new point(-50,50,-50);
tmp02 = new point(50,50,-50);
tmp03 = new point(-50,-50,-50);
tmp04 = new point(50,-50,-50);
tmp05 = new point(-50,50,50);
tmp06 = new point(50,50,50);
tmp07 = new point( -50,-50,50);
tmp08 = new point( 50, -50 ,50 );
}
function rotate(xrot,yrot){
for (i=1;i<=8;i++){
document.all["tmp_zpos0"+i] = (eval("tmp0"+i+".z") * Math.cos(yrot))
- (eval("tmp0"+i+".x") * Math.sin(yrot))
document.all["tmp0"+i+".x"] =
(eval("tmp0"+i+".z")*Math.sin(yrot))+(eval("tmp0"+ i+".x")*Math.cos(yrot));
document.all["tmp0"+i+".z"] =
(eval("tmp0"+i+".y")*Math.sin(xrot))+(eval("docume nt.all.tmp_zpos0"+i)*Math.cos(xrot));
document.all["tmp0"+i+".y"] =
(eval("tmp0"+i+".y")*Math.cos(xrot))-(document.all["tmp_zpos0"+i]*Math.sin(xrot));
document.f01.t01.value = document.f01.t01.value +
document.all["tmp0"+i+".y"] + "\n"
}
setTimeout("rotate(0.02,0.01)", 1000);
}
function runAll (){
mkPoints()
rotate(0.02,0.01)
}
--------

The problem is as follows - I am baffled as to why it appears to retun
Nan or undefined when the values are clearly are there.

Please help,
Thank you
oliverh
Jul 20 '05 #1
4 4697
ma**@oliverhadfield.co.uk (oliver hadfield) writes:
1. first of all

this code requires a form f01 and textarea t01

<form name ="f01">
<textarea name="t01" rows="80" cols="50">
</textarea></form>

2. the javascript is as follows:
----------------------

function point(x,y,z){
this.x = x;
this.y = y;
this.z = z;
}
function mkPoints(){
tmp01 = new point(-50,50,-50);
tmp02 = new point(50,50,-50);
tmp03 = new point(-50,-50,-50);
tmp04 = new point(50,-50,-50);
tmp05 = new point(-50,50,50);
tmp06 = new point(50,50,50);
tmp07 = new point( -50,-50,50);
tmp08 = new point( 50, -50 ,50 );
I would make an array of these points instead of eight global variables.
} function rotate(xrot,yrot){
for (i=1;i<=8;i++){ document.all["tmp_zpos0"+i] = (eval("tmp0"+i+".z") * Math.cos(yrot))
- (eval("tmp0"+i+".x") * Math.sin(yrot))
You never need eval for things like this. It is even much faster to do
it without.

To access the global variabel "tmp0"+i, you can just write
window["tmp0"+i]

You use document.all, which is not as widely applicable as
document.getElementById. I think you just wanted to use "eval" anyway.
You assign directly to the result of document.all[...]. That is most
likely not what you want.

You don't mention an HTML element called "tmp_zpos01", so I guess you
meant to write
eval("tmp_zpos0"+i) = ...
where tmp_zpos01 is a variable?
In that case, you only need one variable, not one for each point.

I would write this line as

var tmp_zpos = window["tmp0"+i].z * Math.cos(yrot) -
window["tmp0"+i].x * Math.sin(yrot);
document.all["tmp0"+i+".x"] =
(eval("tmp0"+i+".z")*Math.sin(yrot))+(eval("tmp0"+ i+".x")*Math.cos(yrot));
window["tmp0"+i].x = window["tmp0"+i].z*Math.sin(yrot) +
window["tmp0"+i].x*Math.cos(yrot);
document.all["tmp0"+i+".z"] =
(eval("tmp0"+i+".y")*Math.sin(xrot))+(eval("docume nt.all.tmp_zpos0"+i)*Math.cos(xrot));
window["tmp0"+i].z = window["tmp0"+i].y*Math.sin(xrot) +
tmp_zpos*Math.cos(xrot);
document.all["tmp0"+i+".y"] =
(eval("tmp0"+i+".y")*Math.cos(xrot))-(document.all["tmp_zpos0"+i]*Math.sin(xrot));
window["tmp0"+i].y = window["tmp0"+i].y*Math.cos(xrot) +
tmp_zpos*Math.sin(xrot);
document.f01.t01.value = document.f01.t01.value +
document.all["tmp0"+i+".y"] + "\n"
Here you use document.all again, where you definitly just meant to use
eval (and you shouldn't use eval either).

document.forms['f01'].elements['t01'].value += window["tmp0"+i].y+"\n";

The problem is as follows - I am baffled as to why it appears to retun
Nan or undefined
*What* returns NaN or undefined? There are not return statements in
the code. I guess it is one of the document.all's that return undefined
because you ask for an element that isn't there.
when the values are clearly are there.


Are they. Have you tested that the values are correct (e.g. by inserting
alerts or using a debugger)?

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
On 12 Oct 2003 16:13:33 -0700
ma**@oliverhadfield.co.uk (oliver hadfield) wrote:
Hello all

I am having a small problem wih a javascript, could anyone help me
please

1. first of all

this code requires a form f01 and textarea t01

<form name ="f01">
<textarea name="t01" rows="80" cols="50">
</textarea></form>

2. the javascript is as follows:
----------------------

function point(x,y,z){
this.x = x;
this.y = y;
this.z = z;
}
function mkPoints(){
tmp01 = new point(-50,50,-50);
tmp02 = new point(50,50,-50);
tmp03 = new point(-50,-50,-50);
tmp04 = new point(50,-50,-50);
tmp05 = new point(-50,50,50);
tmp06 = new point(50,50,50);
tmp07 = new point( -50,-50,50);
tmp08 = new point( 50, -50 ,50 );
}
function rotate(xrot,yrot){
for (i=1;i<=8;i++){
document.all["tmp_zpos0"+i] = (eval("tmp0"+i+".z") *
Math.cos(yrot))
- (eval("tmp0"+i+".x") * Math.sin(yrot))
document.all["tmp0"+i+".x"] =
(eval("tmp0"+i+".z")*Math.sin(yrot))+(eval("tmp0"+ i+".x")*Math.cos(yr
ot));
document.all["tmp0"+i+".z"] =
(eval("tmp0"+i+".y")*Math.sin(xrot))+(eval("docume nt.all.tmp_zpos0"+i
)*Math.cos(xrot));
document.all["tmp0"+i+".y"] =
(eval("tmp0"+i+".y")*Math.cos(xrot))-(document.all["tmp_zpos0"+i]*Mat
h.sin(xrot));
document.f01.t01.value = document.f01.t01.value +
document.all["tmp0"+i+".y"] + "\n"
}
setTimeout("rotate(0.02,0.01)", 1000);
}
function runAll (){
mkPoints()
rotate(0.02,0.01)
}
--------

The problem is as follows - I am baffled as to why it appears to retun
Nan or undefined when the values are clearly are there.


I'm just a newbie in javascript but I see no elements defined to match
your strings in document.all[string] statements.
--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #3
Lee
oliver hadfield said:

Hello all

I am having a small problem wih a javascript, could anyone help me
please

1. first of all

this code requires a form f01 and textarea t01

<form name ="f01">
<textarea name="t01" rows="80" cols="50">
</textarea></form>

2. the javascript is as follows:
----------------------

function point(x,y,z){
this.x = x;
this.y = y;
this.z = z;
}
function mkPoints(){
tmp01 = new point(-50,50,-50);
tmp02 = new point(50,50,-50);
tmp03 = new point(-50,-50,-50);
tmp04 = new point(50,-50,-50);
tmp05 = new point(-50,50,50);
tmp06 = new point(50,50,50);
tmp07 = new point( -50,-50,50);
tmp08 = new point( 50, -50 ,50 );
}
function rotate(xrot,yrot){
for (i=1;i<=8;i++){
document.all["tmp_zpos0"+i] = (eval("tmp0"+i+".z") * Math.cos(yrot))
- (eval("tmp0"+i+".x") * Math.sin(yrot))
document.all["tmp0"+i+".x"] =
(eval("tmp0"+i+".z")*Math.sin(yrot))+(eval("tmp0" +i+".x")*Math.cos(yrot));
document.all["tmp0"+i+".z"] =
(eval("tmp0"+i+".y")*Math.sin(xrot))+(eval("docum ent.all.tmp_zpos0"+i)*Math.cos(xrot));
document.all["tmp0"+i+".y"] =
(eval("tmp0"+i+".y")*Math.cos(xrot))-(document.all["tmp_zpos0"+i]*Math.sin(xrot));
document.f01.t01.value = document.f01.t01.value +
document.all["tmp0"+i+".y"] + "\n"
}
setTimeout("rotate(0.02,0.01)", 1000);
}
function runAll (){
mkPoints()
rotate(0.02,0.01)
}
--------

The problem is as follows - I am baffled as to why it appears to retun
Nan or undefined when the values are clearly are there


What returns NaN? None of the functions you've shown us return anything.
You're using document.all, which is obsolete, and using eval() where it
is not necessary, which is not a good practice.

Jul 20 '05 #4
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<r8**********@hotpop.com>...
ma**@oliverhadfield.co.uk (oliver hadfield) writes:

Hey Lasse,
Thank you very much for looking into the problem in such depth.

1. first of all

this code requires a form f01 and textarea t01

<form name ="f01">
<textarea name="t01" rows="80" cols="50">
</textarea></form>

2. the javascript is as follows:
----------------------

function point(x,y,z){
this.x = x;
this.y = y;
this.z = z;
}
function mkPoints(){
tmp01 = new point(-50,50,-50);
tmp02 = new point(50,50,-50);
tmp03 = new point(-50,-50,-50);
tmp04 = new point(50,-50,-50);
tmp05 = new point(-50,50,50);
tmp06 = new point(50,50,50);
tmp07 = new point( -50,-50,50);
tmp08 = new point( 50, -50 ,50 );


I would make an array of these points instead of eight global variables.


An array. I will have to look into how to do that.
}

function rotate(xrot,yrot){
for (i=1;i<=8;i++){

document.all["tmp_zpos0"+i] = (eval("tmp0"+i+".z") * Math.cos(yrot))
- (eval("tmp0"+i+".x") * Math.sin(yrot))


You never need eval for things like this. It is even much faster to do
it without.

To access the global variabel "tmp0"+i, you can just write
window["tmp0"+i]

You use document.all, which is not as widely applicable as
document.getElementById. I think you just wanted to use "eval" anyway.
You assign directly to the result of document.all[...]. That is most
likely not what you want.

You don't mention an HTML element called "tmp_zpos01", so I guess you
meant to write
eval("tmp_zpos0"+i) = ...
where tmp_zpos01 is a variable?
In that case, you only need one variable, not one for each point.


Good advice, I cut out the eval("tmp_zpos0"+i)
so I re-wrote the following:

window.tmpZpos = (window["tmp0"+i].z * Math.cos(yrot)) -
(window["tmp0"+i].x * Math.sin(yrot));
window["tmp0"+i+".x"] = (window["tmp0"+i].z * Math.sin(yrot)) +
(window["tmp0"+i].x * Math.cos(yrot));
window["tmp0"+i+".z"] = (window["tmp0"+i].y * Math.sin(xrot)) +
(window.tmpZpos * Math.cos(xrot));
window["tmp0"+i+".y"] = (window["tmp0"+i].y * Math.cos(xrot)) -
(window.tmpZpos * Math.sin(xrot));

works perfectly
I would write this line as

var tmp_zpos = window["tmp0"+i].z * Math.cos(yrot) -
window["tmp0"+i].x * Math.sin(yrot);
document.all["tmp0"+i+".x"] =
(eval("tmp0"+i+".z")*Math.sin(yrot))+(eval("tmp0"+ i+".x")*Math.cos(yrot));


window["tmp0"+i].x = window["tmp0"+i].z*Math.sin(yrot) +
window["tmp0"+i].x*Math.cos(yrot);
document.all["tmp0"+i+".z"] =
(eval("tmp0"+i+".y")*Math.sin(xrot))+(eval("docume nt.all.tmp_zpos0"+i)*Math.cos(xrot));


window["tmp0"+i].z = window["tmp0"+i].y*Math.sin(xrot) +
tmp_zpos*Math.cos(xrot);
document.all["tmp0"+i+".y"] =
(eval("tmp0"+i+".y")*Math.cos(xrot))-(document.all["tmp_zpos0"+i]*Math.sin(xrot));


window["tmp0"+i].y = window["tmp0"+i].y*Math.cos(xrot) +
tmp_zpos*Math.sin(xrot);
document.f01.t01.value = document.f01.t01.value +
document.all["tmp0"+i+".y"] + "\n"


Here you use document.all again, where you definitly just meant to use
eval (and you shouldn't use eval either).

document.forms['f01'].elements['t01'].value += window["tmp0"+i].y+"\n";

The problem is as follows - I am baffled as to why it appears to retun
Nan or undefined


*What* returns NaN or undefined? There are not return statements in
the code. I guess it is one of the document.all's that return undefined
because you ask for an element that isn't there.
when the values are clearly are there.


Are they. Have you tested that the values are correct (e.g. by inserting
alerts or using a debugger)?

/L


I was using the textarea t01 to return the results.

Thank you again,

oliverh
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: NotGiven | last post by:
I have display error ON and error reporting to E_ALL. I have a form that opens fine. When you submit it, all the fields that have nothing in them, for example an un-selected radio button, throw...
3
by: DMAC | last post by:
I know I must be missing something pretty obvious, but what setting should I change to get the correct length of my string ie why does the select statement below return 1 when it looks fairly...
4
by: Hal | last post by:
Can someone please tell me what is wrong with this script? <script language="JavaScript"> <!-- function HF_CloseAllChildren() { if (g_win1) != undefined { if ((g_win1) && !(g_win1.closed))...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
10
by: Greg | last post by:
class a { public: int x; private: int y; } class b : public a {
26
by: Frederick Gotham | last post by:
I have a general idea of the different kinds of behaviour described by the C Standard, such as: (1) Well-defined behaviour: int a = 2, b = 3; int c = a + b; (Jist: The code will work...
33
by: coolguyaroundyou | last post by:
Will the following statement invoke undefined behavior : a^=b,b^=a,a^=b ; given that a and b are of int-type ?? Be cautious, I have not written a^=b^=a^=b ; which, of course, is undefined....
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.