![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
P.S. Despite my previous answer I strongly doubt that using JavaScript to write out this chunk of code is the way to go. I can't help but feel that if you can't achieve your intended effect using static HTML and CSS, then you are getting a bit too fiddly with the design of the page. I gather this is yet another stage in your evidently never-ending quest to make this page work as you envision. Perhaps you should step back and get some perspective. If the design goal you are after can be achieved only through dynamically-written code, perhaps you are fighting the medium, and should just fix upon some reasonable values for these elements and move on. Just a thought. JMS |
#3
| |||
| |||
|
|
Investigate the JS "document.write" method to write HTML into your document on the fly. You would use a combination of literal values (HTML code) + variables to write dynamically the HTML you need. An (partial) example: I have written a script with the function: function kakaduTime(offset) When it is called in the page (see below) off we go to my script. A bunch of stuff happens and my script ends with: return ("Right now it is "+kDay+", "+kMonth+" "+kDate+" in Kakadu. This is "+season+", "+seasonDescription[seasonIndex]+". ") Now, in my HTML page I call my function like so: p SCRIPT language="JavaScript">document.write(kakaduTime(10 ))</SCRIPT /p How it works: In the HTML page, within the <p> tags is a call to my script "kakaduTime" with the parameter 10 passed to it, which is mapped to the variable "offset" in the JS function itself. (The value of the parameter – 10 – is beyond the scope of this discussion. It works.) A number of variables are calculated. Then the function returns a character string which is made up of literals (like "Right now it is ") and variable values (like the value of "kDay.") This results in a character string which, today, looks like: "Right now it is Thursday, March 26th in Kakadu. This is Gudjewg, or monsoon season — the time of the heaviest rains. Rivers overflow their banks and wildlife moves to high ground." The in-line JS document.write writes this text into the page dynamically when the page is loaded. I did this so that whenever the page was viewed, the correct day and season would be written into the text of the page dynamically. In a month, if the same page were viewed, it would show that date and perhaps a different season, along with its description. In this case I am using document.write only to write the character string returned by the function call. In your case you will have to write actual HTML code, so you will have to learn how to escape characters so they are not written just as text in your page. JMS WTF |
#4
| |||
| |||
|
|
Investigate the JS "document.write" method to write HTML into your document on the fly. |
|
[...] I did this so that whenever the page was viewed, the correct day and season would be written into the text of the page dynamically. In a month, if the same page were viewed, it would show that date and perhaps a different season, along with its description. In this case I am using document.write only to write the character string returned by the function call. In your case you will have to write actual HTML code, so you will have to learn how to escape characters so they are not written just as text in your page. |
#5
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |