View Full Version : random message display

01-14-2010, 07:48 AM

I have a question and I hope any of you could help me. I want to add a feature on my site where a message is randomly displayed out of a list, like if i wanted the site to randomly display a number from 1-10, every time someone loads the page. Is this possible with html?

01-14-2010, 07:54 AM
With html and javascript yes. With html and php yes. With html alone...no. Where are the messages going to come from?

01-14-2010, 07:54 AM
what do you think is the easiest way, from a database?

01-14-2010, 08:05 AM
could i create an array and use a function to display one at random?

01-14-2010, 09:17 AM
just create an array in javascript.. then make it random display...you won't be needing a database for that..

01-14-2010, 09:26 AM
does anyone know the command line i should use to display a random array. For example, let's just say this is the array i set up

<script type="text/javascript">
var mycars = new Array();
mycars[0] = "1";
mycars[1] = "2";
mycars[2] = "3";



what could be a command i could use?

01-14-2010, 09:55 AM
you can try this (http://www.codeave.com/javascript/code.asp?u_log=7033)

01-18-2010, 09:35 AM
thanks for getting back to me. that's exactly what i needed. i have one more question. lets just say i created a list of like 30 things to say, and i wanted to hide it from the source code. what would you recommend i do?

01-18-2010, 10:11 AM
You can't hide them from the source code. You could store them in a database but then why do you need to hide them? You could put your script in an external js file but that doesn't really hide them. It just moves them.

01-19-2010, 06:30 PM
that's true. idk ive been trying to teach myself some of the database basics. apply myself, you know what i mean?

how hard would it be storing info into a database and retrieving it with javascript?

01-19-2010, 07:13 PM
You wouldn't retrieve the data from the database with javascript. You would use php to randomly pull a record from the database.