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 5 of 5
  1. #1
    a-9
    a-9 is offline
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Document.write error in a simple string.

    I have this piece of code inside an XHTML Strict document:
    Code:
        <script type="text/javascript"><!--//--><![CDATA[//><!--
          var age = 27;
          if (age > 17 && age < 21) {
            document.write("<p>Old enough to vote, too young to drink.</p>");
            }
          //--><!]]>
        </script>
    It does not show up in the broser. (Opera and Firefox)
    Edit: I have realized why I does now shows up: Logic. (I am ashamed)
    The erros below still persist, though.
    JSLint says:Error:
    Implied global: document 3
    Problem at line 3 character 9: document.write can be a form of eval.
    Global age


    I googled for this error but got nothing.
    Thanks in advance for any help.
    Last edited by a-9; 08-28-2008 at 02:54 PM.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    document.write is an HTML DOM feature only and is not available in XHTML or generic XML modes. Look into using the DOM to generate the textnode and element and then insert it in the appropriate place in the DOM tree.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    a-9
    a-9 is offline
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK. That sounds confusing to me. I am a beginner.

    On my way in search of the acknowledgment I expect that soon I am going to master it.

  • #4
    Regular Coder
    Join Date
    Jul 2008
    Posts
    157
    Thanks
    9
    Thanked 13 Times in 13 Posts

    DOM or BOM?

    Just reviewed notes from "Professional JavaScript for Web Developers" and thought: WRITE() and WRITEIN() are BOM (Browser Object Model) document object methods and used in conjunction with .open() and .close()

    Code:
    var newWin = window.open (URL, "newWin", "features");
    newWin.document.open;
    newWin.document.write("______________");
    newWin.document.close():
    .open method called before using .write() and, after writing is complete, call .close(0 to render.

    "Only object that belongs to both DOM and BOM is window.DOCUMENT." [Above is from my notes so don't blame to book for my errors.] And that probably has nothing to do with original query.

  • #5
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by a-9 View Post
    I have this piece of code inside an XHTML Strict document:
    Code:
        <script type="text/javascript"><!--//--><![CDATA[//><!--
          var age = 27;
          if (age > 17 && age < 21) {
            document.write("<p>Old enough to vote, too young to drink.</p>");
            }
          //--><!]]>
        </script>
    It does not show up in the broser. (Opera and Firefox)
    Edit: I have realized why I does now shows up: Logic. (I am ashamed)
    The erros below still persist, though.
    JSLint says:Error:
    Implied global: document 3
    Problem at line 3 character 9: document.write can be a form of eval.
    Global age


    I googled for this error but got nothing.
    Thanks in advance for any help.
    it surly doesnt show up as in your statement age is higher than 21, try it this way for example:
    Code:
    <script language="JavaScript" type="text/javascript">
    
     var age = 27;
          if (age > 17 && age < 28)
            document.write('<p>Old enough to vote, too young to drink.</p>');
    
    
    </script>
    and it will work whatever the doctype is.
    Last edited by sybil6; 09-03-2008 at 01:19 PM.


  •  

    Posting Permissions

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