|
| |
|
|
FlowerPower
Posts: 67 Joined: 4/27/2004 Status: offline
|
Javascript set text in HTML element - 4/27/2004 19:28:27
Greetings - first post here... This may not be a true newbie question, but then I don't feel that experienced still, so I'll ask it here anyway. I have a page where I want to display a random quote on the index page when it opens in the browser. I have made a javascript function that is called in the <body onload> tag. It generates a random number and runs a switch sentence to select from a pool of quotes and depending on the case sets one of these quotes as the text of a string variable. This all works well. The problem is that I then want to display this text in a particular location, e.g. a <p> or <div> or <span> or <table>. I'd rather not use a form element, as a textbox or similar would clash with the look of the page. I don't know how to specify that the string variable should be displayed in the HTML element. document.write overwrites the rest of the stuff in the page (it's a menu sidebar in a frames page, and I have a DHTML pulldown menu higher up on this page - I want to display the quote below the menu). Any ideas will be received gratefully! FlowerPower :o)
|
|
|
|
BobbyDouglas
Posts: 5456 Joined: 5/15/2003 From: Arizona Status: offline
|
RE: Javascript set text in HTML element - 4/27/2004 19:30:27
Welcome to Outfront! Can you use PHP or ASP to create this? Or must you stick with JavaScript?
_____________________________
Arizona Web Design - Mr Bobs Web Design in Arizona The Arizona Web Hosting Challenge
|
|
|
|
FlowerPower
Posts: 67 Joined: 4/27/2004 Status: offline
|
RE: Javascript set text in HTML element - 4/27/2004 20:35:03
Hi, thanks for your speedy reply. Um, I guess I could use ASP. The web server I use does not support PhP, but I know I could use ASP. Better get my book out and peruse that chapter on ASP... I was hoping there was a quick and easy way in JavaScript of naming a specific tag (something along the lines of <p id="quote"> and then setting the value of the element with that name. I searched google for quite a while though and came up with nothing I could use, so began to suspect that maybe I would have to use something other than JavaScript. Thank yoy! FlowerPower
|
|
|
|
puiwaihin
Posts: 1378 From: Taiwan Status: offline
|
RE: Javascript set text in HTML element - 4/30/2004 14:31:21
To do that in Javascript you would need to open the document first. So after the <body> tag write <script language="javascript">document.open()</script> and then when you use the document.write() function the page will not get overwritten.
_____________________________
" Things are always darkest, just before it goes totally black." -Hannibal Smith
|
|
|
|
FlowerPower
Posts: 67 Joined: 4/27/2004 Status: offline
|
RE: Javascript set text in HTML element - 5/2/2004 6:50:21
Strange. The entire site takes up 400 KB as far as I can see, although the web folder is placed inside a larger (FrontPage web) folder containing the site I'm using this school year. Would this larger site be loaded into memory as well, even if those pages are not actually visible in the browser? Or could the considerable loading time be due to a slow web server. The server belongs to the school I work for, and probably has rather limited specs... FP
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|