1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

some javascript help

Discussion in 'HTML & JavaScript' started by dutch85, Jan 24, 2010.

  1. dutch85

    dutch85 Registered Member

    Joined:
    Dec 22, 2009
    Messages:
    52
    Likes Received:
    1
    hello i am extreamly new to javascript and am working on a random quote generator for a myspace app i am using the code from here

    http://www.codelifter.com/main/javascript/randomquote.shtml

    and am currently trying to create a button that will generate another random quote

    i have tried something along the lines of
    Code:
    function generateRandom(){Math.random();}
    
    var Q = Quotation.length;
    var whichQuotation=Math.round(generateRandom()*(Q-1));
    function showQuotation(){document.write(Quotation[whichQuotation]);}
    showQuotation();
    <INPUT TYPE="button" NAME="myButton" VALUE="New Quote"  onClick="generateRandom();">
    
    but it doesnt work can anybody help me with this thanks
     
  2. dutch85

    dutch85 Registered Member

    Joined:
    Dec 22, 2009
    Messages:
    52
    Likes Received:
    1
    i decided to use a refresh button simply because it would multiply my impressions but if anybody could still help me out with this that would be great

    thanks
     
  3. TheGoat

    TheGoat Registered Member

    Joined:
    Oct 1, 2009
    Messages:
    70
    Likes Received:
    85
    First forget about that crap function, the only thing we will take from it is the array.

    Here is your new code:
    Code:
    <script type="text/javascript">
    
    function newContent(show) {
     
         var Quotation = new Array();
    
        Quotation[0] = "Time is of the essence! Comb your hair.";
        Quotation[1] = "Sanity is a golden apple with no shoelaces.";
        Quotation[2] = "Repent! The end is coming, $9.95 at Amazon.";
        Quotation[3] = "Honesty blurts where deception sneezes.";
        Quotation[4] = "Pastry satisfies where art is unavailable.";
        Quotation[5] = "Delete not, lest you, too, be deleted.";
        Quotation[6] = "O! Youth! What a pain in the backside.";
        Quotation[7] = "Wishes are like goldfish with propellors.";
        Quotation[8] = "Love the river's \"beauty\", but live on a hill.";
        Quotation[9] = "Invention is the mother of too many useless toys.";
    
         
         document.getElementById("my_div").innerHTML = Quotation[show];
     
    }
    
    </script>
    
    <INPUT TYPE="button" NAME="myButton" VALUE="New Quote"  onClick="newContent(Math.floor(Math.random()*10));">
    
    <div id="my_div"></div>
    
    Note the number 10 in
    Code:
    <INPUT TYPE="button" NAME="myButton" VALUE="New Quote"  onClick="newContent(Math.floor(Math.random()*[B]10[/B]));">
    That is the number of array elements you have.

    That should work for you.
     
  4. waverly147

    waverly147 Newbie

    Joined:
    Jan 29, 2010
    Messages:
    15
    Likes Received:
    0
    Occupation:
    internet marketer
    Location:
    florida
    I have made a javascript for pingomatic site. It works well as I added in bookmark toolbar and it makes easy to ping. I want to add some more sites in this code but it does not work. Can anybody help me out in that so that I can use huge number of sites in ping list?