javascript fails

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

    javascript fails

    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="javas cript" 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).to Fixed(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.addSepar ators(arr[0]);
    alert("5");
    arr[0] = Number.injectIn toFormat(arr[0].reverse(), '0###',
    true).reverse() ;
    alert("6");
    arr[1] = Number.injectIn toFormat(arr[1], '00', false);
    alert("7");
    return arr.join(',');
    }

    </script>



    Regards /Snedker
  • Kevin Spencer

    #2
    Re: javascript fails

    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:

    Dive into our comprehensive guide to understanding router login processes, IP addresses like 192.168.1.1, 10.0.0.1, and more. Learn how to access and manage your router's settings, check your private IP, and optimize your network using our easy step-by-step guide.


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



    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Logostician
    Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.


    Parabola is a mate of plane.


    "Morten Snedker" <morten_spammen ot_ATdbconsult. dkwrote in message
    news:j9rtm2h7ld 7httbf848u1vf5n bkejafevb@4ax.c om...
    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="javas cript" 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).to Fixed(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.addSepar ators(arr[0]);
    alert("5");
    arr[0] = Number.injectIn toFormat(arr[0].reverse(), '0###',
    true).reverse() ;
    alert("6");
    arr[1] = Number.injectIn toFormat(arr[1], '00', false);
    alert("7");
    return arr.join(',');
    }
    >
    </script>
    >
    >
    >
    Regards /Snedker

    Comment

    Working...