Results 1 to 8 of 8

Thread: Customizing a random quote script

  1. #1
    Join Date
    Feb 2009
    Location
    Kansas City, KS
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Customizing a random quote script

    Okay I need help with this script I found, I'm trying to customize it so members who sign in don't have to manually enter there name. I really don't know anything about javascript so any help would be great.

    SITE

    Code:
    <script language="JavaScript" type="text/javascript"> 
    
    //Comments Section
    //Jim Allen email: tjallen@pipeline.com 
    //Random Greeting Generator and its html and javascript code are
    //copyright 2001 by Thomas James Allen
    
    //script to generate random greetings
    function greetMe(){
    //check to see if personalized
    var cookievalue = getCookie('getyourwebsitehere');
    if (cookievalue == null){firstname = ""}else{firstname = cookievalue};
    //preload greetings
    var say = new Array();
    say[0] = "&nbsp;Welcome8";
    say[1] = "&nbsp;Hello8";
    say[2] = "&nbsp;Good to see you again8";
    say[3] = "&nbsp;What a pleasure it is to see you8";
    say[4] = "&nbsp;7Having a good time, we hope.";
    say[5] = "&nbsp;7Thanks for visiting.";
    say[6] = "&nbsp;Oh aren't you the bomb8";
    say[7] = "&nbsp;You are totally cool8";
    say[8] = "&nbsp;You da bomb8";
    say[9] = "&nbsp;We should do lunch sometime8";
    say[10] = "&nbsp;Yo8";
    say[11] = "&nbsp;Greetings8";
    say[12] = "&nbsp;Come on in8";
    say[13] = "&nbsp;Lovely to see you again8";
    say[14] = "&nbsp;7You made it.";
    say[15] = "&nbsp;7We're glad you're here.";
    say[16] = "&nbsp;Salutations8";
    say[17] = "&nbsp;Hope you'll be staying for lunch8";
    say[18] = "&nbsp;We are graced by your presence8";
    say[19] = "&nbsp;Hi8";
    say[20] = "&nbsp;Hi, how are you8";
    say[21] = "&nbsp;Have a nice visit8";
    say[22] = "&nbsp;Que pasa8";
    say[23] = "&nbsp;Come in, come in8";
    say[24] = "&nbsp;7You are thriving, I see.";
    say[25] = "&nbsp;7Seems like so long since we'd seen you.";
    say[26] = "&nbsp;We open our doors to you8";
    say[27] = "&nbsp;Stay a while8";
    say[28] = "&nbsp;Mouse right this way8";
    say[29] = "&nbsp;I\'ll tell the boss you\'re here8";
    
    //pick a random greeting
    var howmany = 30
    var bRand = 0;
    bRand = Math.random();
    bRand = Math.floor(bRand * howmany);
    //prepare the cookievalue
    if(firstname != ""){sayPers1 = ", " + firstname + ". "}else{sayPers1 = "."};
    if(firstname != ""){sayPers2 = firstname + ", "}else{sayPers2 = ""};
    //prepare and docwrite the greeting
    sayWhat = say[bRand];
    sayWhat = sayWhat.replace("8",sayPers1);
    sayWhat = sayWhat.replace("7",sayPers2);
    sayWhat = "<b>" + sayWhat + "<\/b>"
    document.write(sayWhat);
    document.close()
    }
    
    //below are the cookiemaker scripts
    //this sets any cookies to expire one year after today (in milliseconds!)
    var expiration = new Date();
    expiration.setTime(expiration.getTime() + 24*60*60*365*1000);
    
    //function for retrieving a cookie.
    function getCookie(name){
    var cname = name + "=";
    var dc = document.cookie;
    if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
    begin += cname.length;
    end = dc.indexOf(";", begin);
    if (end == -1) end = dc.length;
    return unescape(dc.substring(begin, end));
    }
    }
    return null;
    }
    
    //function for setting a cookie.
    function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) + 
    ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    ((secure == null) ? "" : "; secure");
    return true;
    }
    
    //function for deleting a cookie.
    function delCookie (name,path,domain) {
    if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
    }
    
    //function to grab info from the cookiemaker form
    function grabInfo(){
    var cookinfo = document.reggy.info.value;
    return cookinfo;
    }
    
    //-->
    
    
    </script><script type="text/javascript">
    
    
    <!--
    greetMe();
    //-->
    
    
    </script>
    <form name="reggy" onsubmit="return setCookie('getyourwebsitehere" id="reggy">
    <table border="1" cellpadding="2" cellspacing="0">
    <tr>
    <td align="right"><b><font face="Arial, Helvetica, sans-serif">Your Name:</font></b></td>
    <td><input type="text" name="info" size="20" ></input></td>
    </tr>
    <tr>
    <td colspan="2">
    <center>
    <p class="buttongroup"><input type='submit' class="button" name="ss3" value='Enter' ></input></p>
    </center>
    I didn't really want to mess around with it 'cause I know even one small mistake can just throw everything off.

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    What are you trying to do? You want to show a random message everytime your member visits your page?

    This is better done with PHP using the rand() function.

    How are you showing the member's name?
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Yes, rangana is right, here this should do half of it:
    Code:
    <?php
    $random = array('One','Two','Three');
    if(!logged_in()){
      echo $random[rand(0,count($random))];
    }
    ?>
    Change the highlighted to the function/variable that says if the user is logged in or not.
    Last edited by Nile; 05-20-2009 at 03:05 AM.
    Jeremy | jfein.net

  4. #4
    Join Date
    Feb 2009
    Location
    Kansas City, KS
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    o-O What? Well I wanted the greetings that flickr has when you log in, so I looked around and found THIS but you have to manually enter your name for it to work. I'm using Ning Networks and instead of having my members manually enter their names I want it to recognize their user account name when they log in. . .I think I just made this a whole lot more complicated.

    Ughz

  5. #5
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Does your host support PHP? And how are you logging in to your site? PHP? Free login script?
    Jeremy | jfein.net

  6. #6
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Quote Originally Posted by AlterPoser View Post
    I'm using Ning Networks and instead of having my members manually enter their names I want it to recognize their user account name when they log in. . .I think I just made this a whole lot more complicated.
    Does Ning allow you to enter your own code? I played around with Ning a while ago and don't remember that being an option. The most they let you do was edit the CSS.

  7. #7
    Join Date
    Feb 2009
    Location
    Kansas City, KS
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Medyman View Post
    Does Ning allow you to enter your own code? I played around with Ning a while ago and don't remember that being an option. The most they let you do was edit the CSS.
    Well they allow you to enter codes threw pages, content boxes, and the analytics section. I think that's pretty much it as for the PHP, I have no clue.

  8. #8
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    In a JS way

    Code:
    var say = ["Quote1", "Quote2", "Quote3"]
    alert(say[Math.floor(Math.random() * say.length)]);

Bookmarks

Posting Permissions

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