469,306 Members | 1,881 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Problem with Opera an IE

Si
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
Si
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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Marcus Bjorke | last post: by
6 posts views Thread by Shaun Fleming | last post: by
28 posts views Thread by Lachlan Hunt | last post: by
18 posts views Thread by David Morris | last post: by
14 posts views Thread by Philip Herlihy | last post: by
5 posts views Thread by Chris Beall | last post: by
5 posts views Thread by Paul Fi | last post: by
4 posts views Thread by VR | last post: by
34 posts views Thread by Simon Wigzell | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.