How do I make this work for W3C?

Discussion in 'Javascript' started by David W. Deley, May 18, 2004.

  1. What do I put for the W3C part of this code?

    function dot(i)
    {
    this.X = Xpos;
    this.Y = Ypos;
    this.dx = 0;
    this.dy = 0;
    if (isNetscape4) {
    this.obj = eval("document.dot" + i);
    } else if (isIE) {
    this.obj = eval("dot" + i + ".style");
    } else if (isW3C) {
    this.obj = ?????????????
    }
    }

    var dots = new Array(nDots);
    var i = 0;
    for (i = 0; i < nDots; i++) {
    dots = new dot(i);
    }
     
    David W. Deley, May 18, 2004
    #1
    1. Advertising

  2. "David W. Deley" <> writes:

    > What do I put for the W3C part of this code?


    Code is *not* obvious, especially without comments. That means
    we have to guess what you want the code to do.

    > function dot(i)
    > {
    > this.X = Xpos;
    > this.Y = Ypos;
    > this.dx = 0;
    > this.dy = 0;
    > if (isNetscape4) {


    Any browser detection almost almways have failures. Trying to detect
    Netscape 4 is not as efficient as detecting the absence of better
    approaches and testing for the success of this one.

    > this.obj = eval("document.dot" + i);


    Never use eval to access properties. Never! (With overwhelming
    probability, you'll never need to use eval at all, since there are
    safer and more efficient alternatives to all the common (mis)uses of
    eval).

    > } else if (isIE) {
    > this.obj = eval("dot" + i + ".style");
    > } else if (isW3C) {
    > this.obj = ?????????????


    I assume that you are trying to find an element with, e.g., id="dot2".

    I recommned this approach:
    ---
    var id = "dot"+i;
    if (document.getElementById) {
    this.obj = document.getElementById(id);
    } else if (document.all) {
    this.obj = document.all[id];
    } else if (document[id]) {
    this.obj = document[id];
    }
    ---
    No browser detection. Testing for known access methods first and
    falling back on less standardized methods. If a browser has both
    document.getElementById and document.layers, it will use the standard
    method (yes, such browsers exist, and would be likely to be
    misidentified as Neetscape 4).

    > dots = new dot(i);


    Traditionally, functions used as constructors are capitalized, so
    I would change "dot" to "Dot".

    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, May 18, 2004
    #2
    1. Advertising

  3. Fabulous. That should work great. Thank you. (I'm modifying code
    someone else wrote.) -D.D.

    Lasse Reichstein Nielsen wrote:
    >
    > "David W. Deley" <> writes:
    >
    > > What do I put for the W3C part of this code?

    >
    > Code is *not* obvious, especially without comments. That means
    > we have to guess what you want the code to do.
    >
    > > function dot(i)
    > > {
    > > this.X = Xpos;
    > > this.Y = Ypos;
    > > this.dx = 0;
    > > this.dy = 0;
    > > if (isNetscape4) {

    >
    > Any browser detection almost almways have failures. Trying to detect
    > Netscape 4 is not as efficient as detecting the absence of better
    > approaches and testing for the success of this one.
    >
    > > this.obj = eval("document.dot" + i);

    >
    > Never use eval to access properties. Never! (With overwhelming
    > probability, you'll never need to use eval at all, since there are
    > safer and more efficient alternatives to all the common (mis)uses of
    > eval).
    >
    > > } else if (isIE) {
    > > this.obj = eval("dot" + i + ".style");
    > > } else if (isW3C) {
    > > this.obj = ?????????????

    >
    > I assume that you are trying to find an element with, e.g., id="dot2".
    >
    > I recommned this approach:
    > ---
    > var id = "dot"+i;
    > if (document.getElementById) {
    > this.obj = document.getElementById(id);
    > } else if (document.all) {
    > this.obj = document.all[id];
    > } else if (document[id]) {
    > this.obj = document[id];
    > }
    > ---
    > No browser detection. Testing for known access methods first and
    > falling back on less standardized methods. If a browser has both
    > document.getElementById and document.layers, it will use the standard
    > method (yes, such browsers exist, and would be likely to be
    > misidentified as Neetscape 4).
    >
    > > dots = new dot(i);

    >
    > Traditionally, functions used as constructors are capitalized, so
    > I would change "dot" to "Dot".
    >
    > /L
    > --
    > Lasse Reichstein Nielsen -
    > DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    > 'Faith without judgement merely degrades the spirit divine.'
     
    David W. Deley, May 18, 2004
    #3
    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. Alfonso Alvarez
    Replies:
    2
    Views:
    694
    Alfonso Alvarez
    May 13, 2004
  2. Fredrik Elestedt

    W3C validation

    Fredrik Elestedt, Nov 25, 2004, in forum: ASP .Net
    Replies:
    15
    Views:
    1,171
  3. Kenneth Keeley

    How to make ASP Code Validate to a W3C Standard

    Kenneth Keeley, Dec 7, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    429
    Johann MacDonagh
    Dec 9, 2004
  4. Frank
    Replies:
    9
    Views:
    1,590
    David Dorward
    May 3, 2004
  5. Xeno Campanoli
    Replies:
    1
    Views:
    351
    James Britt
    Jul 1, 2005
Loading...

Share This Page