Click to See Complete Forum and Search --> : Help with random quote box


nealbo
08-31-2003, 06:08 AM
Ok, lavalamp gave me this script to make a random quote generator. It works great, but I can't manage to figure out how to put a page break within a quote. i.e for a quote to look like this:

Quote line 1
Quote line 2

when I try this I get errors and when I try <br> I get the br showing up in the quote. How could i achieve this?

<html>

<head>

<title>Random Quotation</title>

<script type="text/javascript"><!--

var quotation=new Array();
quotation[0]="An eye for an eye, a tooth for a tooth.";
quotation[1]="Never drink yello snow.";
quotation[2]="Lavalamp is great!";

function randq(){

document.getElementById("hi").replaceChild(document.createTextNode(quotation[Math.round(Math.random()*(quotation.length-1))]), document.getElementById("hi").firstChild);}

//--></script>

</head>

<body onload="randq();">

<form>

<textarea rows="10" cols="50" id="hi">
Quote 1: An eye for an eye, a tooth for a tooth.
Quote 2: Never drink yello snow.
Quote 3: Lavalamp is great!
</textarea><!-- Enter some quotes in here in case the users don't have javascript enabled. -->

<br><br>

<input type="button" value="New Random Quotation" onclick="randq();">

</form>

</body>

</html>

please help...

Nevermore
08-31-2003, 08:37 AM
It's either put \n where you want to have a line break, or just physically put in a line break. E.g. quote1="SJsdsdsmds
sd,jasjfdsad";
I can't remember which.

David Harrison
08-31-2003, 09:18 AM
I think it should be \n.

nealbo
08-31-2003, 12:24 PM
The physically putting the line break in, doesn't work - I get errors in frontpage, and the \n only seems to put a few spaces in between the 2 intended lines.

nealbo
08-31-2003, 12:27 PM
actually, i just tried putting in lots of \n's and it worked. When I just put spaces in between, it wasn't working properly, and things werent showing up how they should have been. Anyways, the \n thing works - thanks!

nealbo
08-31-2003, 12:35 PM
Oh while i'm here, i might aswell ask, what would I type to change the colour and alignement of certain words within the quotes?

David Harrison
08-31-2003, 01:03 PM
As far as I know, you can't. If you want to change the colour of all the text you can add this:

style="background-color:#ffffff;color:#ff0000;"

to the textarea tag. This will leave the background white and change the text colour to red. The background colour is only there because when validating CSS it says you need a background colour where ever you specify a text colour.

Edit: If you want to change the alignment you could always add lots of spaces until you get the word/phrase more or less where you want it.

nealbo
08-31-2003, 01:19 PM
Ok, the colour wasnt something i really needed, at least i got the \n bit sorted out - thanks for your help!

David Harrison
08-31-2003, 01:21 PM
Happy to help. :)