469,306 Members | 1,881 Online

# Problem with Opera an IE

Hi,

I'll start by saying I'm a complete newbie, this is the first time I
have used Javascript.

The code below I have written to calculate distance/bearings and times
from a grid reference.

It works absolutely fine in Opera 7.11, but in IE it throws up an
"object doesn't support this operation or method" error.

Any help/suggestions to where I have gone wrong and how I can get this
working in IE would be greatly appreciated.

Cheers Si,

###############CODE###################

function distance(form) {
var x1 = eval(form.x1.value);
var y1 = eval(form.y1.value);
var x2 = eval(form.x2.value);
var y2 = eval(form.y2.value);
var sd = eval(form.s.value);
var xdiff = x2 - x1;
var ydiff = y2 - y1;
var y = Math.pow((xdiff * xdiff + ydiff * ydiff), 0.5)/10;
if (Math.atan2((y2 - y1),-(x2 - x1)) * (180 / Math.PI) - 90 < 0) {
var b = Math.atan2((y2 - y1),-(x2 - x1)) * (180 / Math.PI) + 270;
}
else {
var b = Math.atan2((y2 - y1),-(x2 - x1)) * (180 / Math.PI) - 90;
}
var t = y / sd;
form.distance.value = Math.round(10*y)/10
form.time.value = (Math.round(10*t)/10)*60
form.bear.value = Math.round(b)
}
###########################################
Jul 20 '05 #1
3 2284 s.***@cwcom.net (Si) writes:
The code below I have written to calculate distance/bearings and times
from a grid reference.

It works absolutely fine in Opera 7.11, but in IE it throws up an
"object doesn't support this operation or method" error.
It would be very helpful to know which line the error comes from,
what the form contains and how the function is called.

function distance(form) {
var x1 = eval(form.x1.value);
The "eval" function is a very slow way to turn a string into a number
(by a factor of 80 in some browsers). The fastest way us to use a
unary prefix plus. I.e.,

var x1 = +(form.x1.value);

You will probably never need to use "eval" for anything. There are
better and faster ways of solving most problems that a normal page
author runs into. Don't trust solutions that use "eval".
form.distance.value = Math.round(10*y)/10

You have an input element with the name "distance". IE makes a global
variable with that name that refers to the input element. However,
that overwrites your function called "distance". Change the name
of either the input element or the function.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Lasse,

I Changed both things you suggested and it works great now.

Many Thanks.

Si,

Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<r8**********@hotpop.com>...
s.***@cwcom.net (Si) writes:
The code below I have written to calculate distance/bearings and times
from a grid reference.

It works absolutely fine in Opera 7.11, but in IE it throws up an
"object doesn't support this operation or method" error.

It would be very helpful to know which line the error comes from,
what the form contains and how the function is called.

function distance(form) {
var x1 = eval(form.x1.value);

The "eval" function is a very slow way to turn a string into a number
(by a factor of 80 in some browsers). The fastest way us to use a
unary prefix plus. I.e.,

var x1 = +(form.x1.value);

You will probably never need to use "eval" for anything. There are
better and faster ways of solving most problems that a normal page
author runs into. Don't trust solutions that use "eval".
form.distance.value = Math.round(10*y)/10

You have an input element with the name "distance". IE makes a global
variable with that name that refers to the input element. However,
that overwrites your function called "distance". Change the name
of either the input element or the function.

/L

Jul 20 '05 #3
JRS: In article <a7**************************@posting.google.com >, seen
in news:comp.lang.javascript, Si <s.***@cwcom.net> posted at Fri, 31 Oct
2003 15:46:09 :-

if (Math.atan2((y2 - y1),-(x2 - x1)) * (180 / Math.PI) - 90 < 0) {
var b = Math.atan2((y2 - y1),-(x2 - x1)) * (180 / Math.PI) + 270;
}
else {
var b = Math.atan2((y2 - y1),-(x2 - x1)) * (180 / Math.PI) - 90;
}

If that's to convert (X, Y) to bearing from North, there must be an
easier way. Try exchanging X & Y, to get +-180 deg from North.

B = Math.atan2(X, Y)*180/Math.PI // -180<B<=+180
B = (360+Math.atan2(X, Y)*180/Math.PI)%360 // 0<=B<360

Unless the span is certainly small, you should warn about approximations
die to the Non-Flat Earth.

--