Problem with Opera an IE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Si

    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.va lue);
    var y1 = eval(form.y1.va lue);
    var x2 = eval(form.x2.va lue);
    var y2 = eval(form.y2.va lue);
    var sd = eval(form.s.val ue);
    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.v alue = Math.round(10*y )/10
    form.time.value = (Math.round(10* t)/10)*60
    form.bear.value = Math.round(b)
    }
    ############### ############### #############
  • Lasse Reichstein Nielsen

    #2
    Re: Problem with Opera an IE

    s.e.r@cwcom.net (Si) writes:
    [color=blue]
    > 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.[/color]

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

    [color=blue]
    >
    > function distance(form) {
    > var x1 = eval(form.x1.va lue);[/color]

    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".
    [color=blue]
    > form.distance.v alue = Math.round(10*y )/10[/color]

    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 - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Si

      #3
      Re: Problem with Opera an IE

      Lasse,

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

      Many Thanks.

      Si,



      Lasse Reichstein Nielsen <lrn@hotpop.com > wrote in message news:<r80t7xxp. fsf@hotpop.com> ...[color=blue]
      > s.e.r@cwcom.net (Si) writes:
      >[color=green]
      > > 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.[/color]
      >
      > It would be very helpful to know which line the error comes from,
      > what the form contains and how the function is called.
      >
      >[color=green]
      > >
      > > function distance(form) {
      > > var x1 = eval(form.x1.va lue);[/color]
      >
      > 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".
      >[color=green]
      > > form.distance.v alue = Math.round(10*y )/10[/color]
      >
      > 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[/color]

      Comment

      • Dr John Stockton

        #4
        Re: Problem with Opera an IE

        JRS: In article <a7e8542a.03103 11546.241687ca@ posting.google. com>, seen
        in news:comp.lang. javascript, Si <s.e.r@cwcom.ne t> posted at Fri, 31 Oct
        2003 15:46:09 :-[color=blue]
        >
        >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;
        >}[/color]


        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.demo n.co.uk/js-index.htm> JS maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

        Comment

        Working...