SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript problem (I cannot be more thorough)

    I'm sorry for the name of a topic that is not descriptive enough, but I couldn't find a short descriptive title.

    I have two almost identical pages. Actually I don't know how to describe my problem...
    The problem has something to do with document.write. It doesn't work as I thought it would.

    It's best that you check out both examples and go through source code because I have written comments to specify my problem.

    test #1
    test #2

    The first example works like a charm but the second one doesn't.

    What I want is a page made entirely with document.write().

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are using the same incarerators (sp?) as you have in your string.

    Line:

    document.write("<table><thead><tr><td class="head">x</td><td class="head">x<sup>2</sup></td><td class="head">log<sub>10</sub>(x)</td><td class="head">log<sub>2</sub>(x)</td><td class="head"><nobr>(1 + 1/x)<sup>x</sup> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp(e)</nobr></td><td class="head">x (16)</td><td class="head">x (2)</td></tr></thead><tbody>");

    You'll notice you use " to state the input to the function write - but then you also use " inside the input itself.
    This causes the function to assume that the next part is not text - but rather syntax - and it will fall over.

    To prevent this - use '' for the leading and trailing " in your calls to the write method.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two methods to solve your problem. Use double quotes for the document.write and single quotes for the HTML contained

    document.write("<table><thead><tr><td class='head'>x</td><td class='head'>x<sup>2</sup></td><td class='head'>log<sub>10</sub>(x)</td><td class='head'>log<sub>2</sub>(x)</td><td class='head'><nobr>(1 + 1/x)<sup>x</sup> (e)</nobr></td><td class='head'>x (16)</td><td class='head'>x (2)</td></tr></thead><tbody>");

    Or, escape any double quotes within the document.write statment thus telling the script engince to interpret those as text. Use the standed escaping character, the backslash

    document.write("<table><thead><tr><td class=\"head\">x</td><td class=\"head\">x<sup>2</sup></td><td class=\"head\">log<sub>10</sub>(x)</td><td class=\"head\">log<sub>2</sub>(x)</td><td class=\"head\"><nobr>(1 + 1/x)<sup>x</sup> (e)</nobr></td><td class=\"head\">x (16)</td><td class=\"head\">x (2)</td></tr></thead><tbody>");

    That should do it
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Beetle - what's wrong with the simple two character changes of the document.write('') ??

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nuthin! Just alternate the quotes will ya!
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

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