Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript need help….

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #24883

    I m using a script for randomly calling a text on my page using

    Code:
    Math.floor(Math.random()*(quotes.length))

    this code running perfectly when i click on my page or refresh it… is that possible to autorate the quotes after sometime

    u can see the live example playbackgroup.com right panel in top box where quotes are coming

    #57794
    AshtonSanders
    Participant

    I’m lost. Can you define "autorate" ?

    #57796
    apostrophe
    Participant
    "AshtonSanders" wrote:
    I’m lost. Can you define "autorate" ?

    I think he means rotate. ie. Refresh the quote after a specified amount of time.

    #58171

    i mean refreshing a quote automatically after sometime

    #58172
    cssfreak
    Member
    Code:
    function rotateQuotes()
    {
    Math.floor(Math.random()*(quotes.length))
    setTimeout(“rotateQuotes()”,100000);
    }

    try this let me know if this helps u

    #58175

    At the moment you are just ouputting the quote from javascript using document.write – but you can’t change existing text using document.write, as it only adds contents to the page. You should really learn a DOM manipulation library like jQuery, it really makes doing this kind of thing a lot easier.

    With jQuery your function might look like the following (including cssfreaks changes):

    HTML:

    Code:

    What the world thinks?

    Javascript:

    Code:
    function rotateQuotes() {
    var whichquote = Math.floor(Math.random()*(quotes.length));
    $(‘#quote’).html(quotes[whichquote]);
    setTimeout(“rotateQuotes()”,100000);
    }

    By the way you can only have one <h1> per page, so you should really change those to h2 or h3.

    #58279

    hi daves,
    i told u in my last post tht u r really a GENIUS.. :D

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.