Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    random message display

    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?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    With html and javascript yes. With html and php yes. With html alone...no. Where are the messages going to come from?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Jan 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what do you think is the easiest way, from a database?

  • #4
    New Coder
    Join Date
    Jan 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    could i create an array and use a function to display one at random?

  • #5
    New Coder
    Join Date
    Dec 2007
    Posts
    82
    Thanks
    10
    Thanked 0 Times in 0 Posts
    just create an array in javascript.. then make it random display...you won't be needing a database for that..

  • #6
    New Coder
    Join Date
    Jan 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #7
    New Coder
    Join Date
    Dec 2007
    Posts
    82
    Thanks
    10
    Thanked 0 Times in 0 Posts
    you can try this

  • #8
    New Coder
    Join Date
    Jan 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    New Coder
    Join Date
    Jan 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #11
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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/
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •