Javascript set text in HTML element (Full Version)

All Forums >> [Web Development] >> Microsoft FrontPage Help



Message


FlowerPower -> 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 -> 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?




FlowerPower -> 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




BobbyDouglas -> RE: Javascript set text in HTML element (4/27/2004 20:41:39)

Well it is a little bit easier than you will expect:

http://www.expinion.net/software/app_quote.asp
http://www.digiappz.com/freekot2.asp?id=6

If you are just starting ASP you might want to check out some free scripts to see how others use ASP @ www.hotscripts.com

Show us the link once you get it set up [:)]




FlowerPower -> RE: Javascript set text in HTML element (4/27/2004 20:56:03)

Thanks!
I've dabbled in PhP and have programmed quite a bit in VB before, so ASP is not a big problem to get used to.

As for the link, the site won't be up for another month and a half yet - it's a site for my high school IT students, and will be replacing the site I currently have up, but I'll wait till the end of the semester before I do the switch.

FP[:)]




FlowerPower -> RE: Javascript set text in HTML element (4/28/2004 19:38:11)

Thanks, got it working with a tiny bit of ASP. I have put it up for testing, but there are no links going to it yet, as it is not intended to be put into use for another couple of months. Here's what's up so far:

http://community.ismanila.com/staff/brokvams/web0405/index.htm

FlowerPower [:)]




BobbyDouglas -> RE: Javascript set text in HTML element (4/28/2004 20:31:46)

Yikes!! That pages takes forever to load.

The quote looks very nice though [:)]




puiwaihin -> 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.




FlowerPower -> 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




BobbyDouglas -> RE: Javascript set text in HTML element (5/2/2004 12:53:13)

Would this larger site be loaded into memory as well, even if those pages are not actually visible in the browser?
- Browsers only load the code, and any coorsponding tags in the code that inserts something else (ie the external javascript files/external CSS)

Or could the considerable loading time be due to a slow web server.
- It was prolly a slow server at the time. Loads fine for me now. [:)]




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0625