Re: random quote using javascript

by "Martin Clifford" <MLC1(at)nrc.gov>

 Date:  Fri, 17 May 2002 08:19:43 -0400
 To:  <magic32(at)jps.net>,
<hwg-techniques(at)mail.hwg.org>
  todo: View Thread, Original
You'd have to use DHTML to dynamically change the text in the random fact.

Stylesheet Setup:

<style type=3D"text/css">

#quote {position: absolute; top: 10px; left: 10px; border: 2px solid =
black; background-color: white; color: black; font-family: verdana, =
sans-serif;}

</style>

JavaScript Setup:

<script language=3D"JavaScript">
<!--

/*Use your random quote script here, but when the user calls the writeQuote=
() function that reloads the page on link click, use this instead*/

document.all['quote'].innerHTML =3D "<b>Thomas Jefferson once said...</b>";=


=AF>
</script>

Then, in your body, set up your div.  You can create the writeQuote =
function however you want.  In this case, I created the function to take a =
single argument (which is good for doing onmouseover tooltips).

<div id=3D"quote">
Click <a href=3D"#" onClick=3D"writeQuote('Hi Mr. Postman!'); return =
false;">here</a> to write a new line!
</div>

Hope this helps.  The full HTML is below. :o)

Martin

<html>

<head>

<title>Dynamic HTML</title>

<style type=3D"text/css">
<!-- hide

#quote {position: absolute; top: 10px; left: 10px; border: 2px solid =
black; background-color: white; color: black;=20
font-family: verdana, sans-serif; padding: 3px; width: 350px;}

show -->
</style>

<script language=3D"JavaScript">
<!-- hide

function writeQuote(quote)
{
	document.all['quote'].innerHTML =3D "<b>" + quote + "</b>";
}

show -->
</script>

</head>

<body>

<div id=3D"quote">
Click <a href=3D"#" onClick=3D"writeQuote('Hi Mr. Postman!'); return =
false;">here</a> to write a new line!
</div>

</body>

</html>

>>> "Roger Harness" <magic32(at)jps.net> 05/17/02 02:07AM >>>
techniquers,

right now i have a simple 'random' javascript function which will write 1 =
of
approximately 20 facts on a page i have, whenever any body goes to the =
page,
refreshes the page, or clicks on the "another random fact?" link, which
simply uses a "window.location.reload();" method (i hope my terminology is
right).

My question is, is there a fairly simple way to write a new random fact =
when
somebody clicks the "another random fact" link, to my page *without* =
having
to refresh the entire page each time?

didn't really want to use a text box, as that'd *really* throw off my =
design
:)

anyways, any suggestions would be greatly appreciated!

tia,

-Roger Harness

**go LAKERS!**

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA