javascript fails

Discussion in 'ASP .Net' started by Morten Snedker, Nov 30, 2006.

  1. If my question is off this group, please point me in the right
    direction.

    Here goes:

    My scipt fails between alert-2 and alert-3 with

    "Object doesn't support this property or method" (freely translated
    from Danish).

    Any idea what could be wrong?

    The code is a rip-off from
    http://xaprb.com/articles/number-formatting-demo.html.

    <script language="javascript" type="text/javascript" >

    function fNr(context){
    alert("1");
    var val = (context == null) ? new Number(this) : Math.abs(this);
    alert("2");
    var arr = val.round(2).toFixed(2).split(',');
    alert("3");
    arr[0] = (val < 0 ? '-' : '') + String.leftPad((val < 0 ?
    arr[0].substring(1) : arr[0]), 1, '0');
    alert("4");
    arr[0] = Number.addSeparators(arr[0]);
    alert("5");
    arr[0] = Number.injectIntoFormat(arr[0].reverse(), '0###',
    true).reverse();
    alert("6");
    arr[1] = Number.injectIntoFormat(arr[1], '00', false);
    alert("7");
    return arr.join(',');
    }

    </script>



    Regards /Snedker
    Morten Snedker, Nov 30, 2006
    #1
    1. Advertising

  2. In the context of your ripped-off version, "this" is the HTML document. In
    the context of the script you ripped off, "this" is a JavaScript object,
    specifically, the JavaScript Number object:

    http://www.comptechdoc.org/independent/web/cgi/javamanual/javanumber.html

    The author of the script has extended the Number object via prototyping.The
    following tutorial should help you to understand how it works:

    http://www.javascriptkit.com/javatutors/proto.shtml

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Logostician
    http://unclechutney.blogspot.com

    Parabola is a mate of plane.


    "Morten Snedker" <morten_spammenot_ATdbconsult.dk> wrote in message
    news:...
    > If my question is off this group, please point me in the right
    > direction.
    >
    > Here goes:
    >
    > My scipt fails between alert-2 and alert-3 with
    >
    > "Object doesn't support this property or method" (freely translated
    > from Danish).
    >
    > Any idea what could be wrong?
    >
    > The code is a rip-off from
    > http://xaprb.com/articles/number-formatting-demo.html.
    >
    > <script language="javascript" type="text/javascript" >
    >
    > function fNr(context){
    > alert("1");
    > var val = (context == null) ? new Number(this) : Math.abs(this);
    > alert("2");
    > var arr = val.round(2).toFixed(2).split(',');
    > alert("3");
    > arr[0] = (val < 0 ? '-' : '') + String.leftPad((val < 0 ?
    > arr[0].substring(1) : arr[0]), 1, '0');
    > alert("4");
    > arr[0] = Number.addSeparators(arr[0]);
    > alert("5");
    > arr[0] = Number.injectIntoFormat(arr[0].reverse(), '0###',
    > true).reverse();
    > alert("6");
    > arr[1] = Number.injectIntoFormat(arr[1], '00', false);
    > alert("7");
    > return arr.join(',');
    > }
    >
    > </script>
    >
    >
    >
    > Regards /Snedker
    Kevin Spencer, Nov 30, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders
    Replies:
    1
    Views:
    665
    John Saunders
    Nov 18, 2003
  2. =?Utf-8?B?RFNpcHA=?=

    javascript dopostback fails

    =?Utf-8?B?RFNpcHA=?=, Jan 17, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,593
    David Jessee
    Jan 20, 2005
  3. Dag Sunde
    Replies:
    8
    Views:
    3,080
    Andrew T.
    May 10, 2006
  4. Replies:
    2
    Views:
    286
    Grant Wagner
    Dec 23, 2004
  5. dayo
    Replies:
    11
    Views:
    336
    Ilya Zakharevich
    Dec 16, 2005
Loading...

Share This Page