...

View Full Version : random message display



cartboy
01-14-2010, 07:48 AM
Hello,

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?

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

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

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

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

cartboy
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";

//command

</script>

what could be a command i could use?

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

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

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

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

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

http://www.tizag.com/mysqlTutorial/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum