473,385 Members | 1,492 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,385 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 4701
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....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.