Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question Can someone get this to validate?

    Hi Gang,
    I've been getting my web site code validated, and I have run across a little problem:
    Code:
    document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
    The above code is throwing an error when I try to validate. It keeps complaining about the three </div> tags in this string. I think there is a way to wrap this code so that this will validate, but I'm not sure how to do it. Can someone help me out?
    Thanks in advance,
    Andy
    (Management+Coworkers)<>Logic

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    its usually because of the </ in close proximity..try this
    Code:
    '<' + '/' + 'div>'

  • #3
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    This is described in Section B.3.2.1 of the HTML 4.01 Specification. It also shows an easier way to avoid that character combination (<\/).
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Hey Arbitrator & Shyam,
    thanks for the quick replies. Shyam, your solution worked. I do understand what Arbitrator is saying about there being an easier way.... I saw something on using the '\' to fix this, but when I tried it the script didn't run. I don't know if I did something wrong or not....
    Arbitrator, could you please change this string of code so that I know it is correct and then I can see if I did something wrong?
    Thanks again,
    Andy
    (Management+Coworkers)<>Logic

  • #5
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    You just stick the symbol into the middle of every </ combination. It’s effectively escaping the forward slash (doing nothing), to keep the two characters apart.

    Here’s a functional example. It uses a three-div structure as seen in your own code.

    I didn’t use your exact code, however, because it references things I don’t have access to and makes use of bad practice (inline CSS). document.write() itself is also bad practice, but for the sake of demonstration, I left it alone.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
    
    <html lang="en-US">
      <head>
    
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
        <title>HTML 4.01 Strict Document</title>
    
        <meta name="Author" content="Patrick Garies">
    
        <style type="text/css">
          * { margin: 0; }
          html { padding: 1em; }
          *#container {
            border: 1px solid;
            }
          *#container div {
            margin: 1em;
            border: 1px solid #ccc;
            background-color: #eee;
            }
          *#container div + div {
            font-variant: small-caps;
            }
          span.date { font-weight: bold; }
        </style>
    
      </head>
      <body>
    
        <div>
          <script type="text/javascript">
            var date = new Date();
            var days = [
              "Sunday",
              "Monday",
              "Tuesday",
              "Wednesday",
              "Thursday",
              "Friday",
              "Saturday"
              ]
            var day = days[date.getDay()];
            document.write("<div id='container'>\
              <div>Today is <span class='date'>" + day + "<\/span>.<\/div>\
              <div>It is day " + date.getDate() + " of this month.<\/div>\
              <\/div>");
          </script>
        </div>
    
      </body>
    </html>
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #6
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Ok Arbitrator,
    Thanks. I got this script off of the net, not really the best web coder. How would you go about replacing document.write? I think I see a re-write of this script coming, maybe a chance to learn something while I'm at it!
    Andy
    (Management+Coworkers)<>Logic

  • #7
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    Quote Originally Posted by steamngn View Post
    How would you go about replacing document.write?
    An example is below; this uses basic DOM methods. This would go in the head of the document. All of the CSS would be assigned through classes or IDs in style sheets. The insertion of the content would be done during the load of the document using events like load or DOMContentLoaded.

    This is much more verbose, so some people use Microsoft’s shortcut of innerHTML. You should at least know how to do things this way though since not everyone’s going to support Microsoft’s extensions. You should also know it since document.write() doesn’t work in XML, including XML languages such as XHTML.

    Code:
    var div1 = document.createElement("div");
    var div2 = document.createElement("div");
    var div3 = document.createElement("div");
    div1.id = divID;
    div1.className = yourClass1;
    div2.id = divID + "1";
    div2.className = div3.className = innerDiv;
    div3.id = divID + "2";
    div1.appendChild(div2);
    div2.appendChild(div3);
    div3.appendChild(content);
    document.body.appendChild(div1);
    Blue variables reference content not shown here.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #8
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Ok Arbitrator,
    I think I get it...
    I will try to put this to use for this page I am trying to validate, and see if I can get it to work. I will let you know how I make out! (Or I'll be bakc crying for help! )
    (Management+Coworkers)<>Logic


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •