SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Jul 31, 2002, 03:47 #1
- 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().
-
Jul 31, 2002, 04:13 #2
- 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>       (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 |=---
-
Jul 31, 2002, 10:30 #3
- 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
-
Jul 31, 2002, 10:31 #4
- 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 |=---
-
Jul 31, 2002, 10:49 #5
Bookmarks