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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Javascript PopUp Help

    How would i make a pop up with one of three randomly generated messages. I dont want this pop up to show in a new window.

    This is what I have so far.

    Code:
    <SCRIPT language="JavaScript">
    function get_random()
    {
        var ranNum= Math.floor(Math.random()*3);
        return ranNum;
    }
    
    function getaQuote()
    {
       	var whichQuote=get_random();
    	var contents = '<html><head><title>Counter Window<\/title></head></html>';
        var quote=new Array(3)
         quote[0]="Switch to Firefox for a safer, more customizable web experience.";
         quote[1]="Don't forget to sign the guestbook!";
         quote[2]="Don't forget to vote in the weekly poll!";   
      
       alert(quote[whichQuote]);
    }
    
    getaQuote()
    </SCRIPT>
    I found this code on the internet but it doesnt have the randomly gen. msg.

    Code:
    <script language="JavaScript" type="text/javascript">
    <!-- Copyright 2003, Sandeep Gangadharan -->
    <!-- For more free scripts go to http://sivamdesign.com/scripts/ -->
    <!--
    var y1 = 140;   // change the # on the left to adjuct the Y co-ordinate
    (document.getElementById) ? dom = true : dom = false;
    
    function hideIt() {
      if (dom) {document.getElementById("layer1").style.visibility='hidden';}
    }
    
    function showIt() {
      if (dom) {document.getElementById("layer1").style.visibility='visible';}
    }
    
    function placeIt() {
      if (dom && !document.all) {document.getElementById("layer1").style.top = window.pageYOffset + (window.innerHeight - (window.innerHeight-y1)) + "px";}
      if (document.all) {document.all["layer1"].style.top = document.documentElement.scrollTop + (document.documentElement.clientHeight - (document.documentElement.clientHeight-y1)) + "px";}
      window.setTimeout("placeIt()", 10); }
    // -->
    </script>
    ...then in the body part:

    Code:
    <div id="layer1" style="position:absolute; left:20; width:410px; height:10; visibility:hidden">
       <font face="verdana, arial, helvetica, sans-serif" size="2">
        <div style="float:left; background-color:yellow; padding:3px; border:1px solid black">
        <span style="float:right; background-color:gray; color:white; font-weight:bold; width='20px'; text-align:center; cursor:pointer" onclick="javascript:hideIt()">&nbsp;X&nbsp;</span>
        Don't forget to sign the guestbook.</div>
       </font>
    </font>
    </div>
    Last edited by pen_lord2000; 09-14-2008 at 01:20 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,925
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Please edit your post so as to use CODE tags.

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    bump bump bump

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,077
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb Consider this

    I'm not sure I understand so this is only a guess as to what you want to do.
    PHP Code:
    <html>
    <
    head>
    <
    title>Randome Messages</title>
    <
    style type="text/css">
      
    span position:absolutetop:100pxleft:200px
               
    background-color:#CCC;
               
    font-weight:bold;
               
    width:200px;
               
    text-align:center;
               
    cursor:pointer;
           }
    </
    style>
      
    <
    SCRIPT type="text/javascript" language="JavaScript">
     var 
    quote = [
                   
    "The more quotes, the fewer repeated messages",
                   
    "The fewer quotes, the more repeated messages",
                  
    "Switch to Firefox for a safer, more customizable web experience.",
                  
    "Don't forget to sign the guestbook!",
                  
    "Don't forget to vote in the weekly poll!"
                 
    ];   // add more quotes separated by ',' EXCEPT the last one

    function getaQuote() {
      var 
    whichQuote quote[Math.floor(Math.random()*quote.length)];
      return  
    whichQuote;
    }
    function 
    changeQuote() {
      
    document.getElementById('rmsg').innerHTML getaQuote();
    //  document.getElementById('layer1').style.display.visibility = 'visible';
    }
    // getaQuote()
    </SCRIPT>

    </head>
    <body>
    <!-- call onload="changeQuote()" in <body> if desired to remove buttons -->

     <span id="rmsg">
      &nbsp;X&nbsp; Random message to be replaced here.
     </span>
    <p>
    <button onclick="alert(getaQuote())">Alert Test</button>
    <button onclick="changeQuote()">Span Test</button>
    </body>
    </html> 
    Remove the test buttons and use onload in <body> for the final version if that is your desire.
    Note the limited randomness with so few quotes.
    Change <span> to <div> if desired as in your original code.

  • Users who have thanked jmrker for this post:

    pen_lord2000 (09-15-2008)


  •  

    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
    •