...

View Full Version : Javascript PopUp Help



pen_lord2000
09-14-2008, 01:12 AM
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. :confused:

This is what I have so far.


<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.


<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:


<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>

Philip M
09-14-2008, 09:14 AM
Please edit your post so as to use CODE tags.

pen_lord2000
09-14-2008, 03:59 PM
bump bump bump

jmrker
09-15-2008, 04:11 AM
I'm not sure I understand so this is only a guess as to what you want to do. :confused:


<html>
<head>
<title>Randome Messages</title>
<style type="text/css">
span { position:absolute; top:100px; left: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum