Help - Search - Members - Calendar
Full Version: Birthday script
HTMLHelp Forums > Programming > Client-side Scripting
shammo
Help please

<script language="JavaScript">

var arrBday = [
['Bob','11/23/1973'],
['Peter','9/22/1977'],
['John','9/22/1999']
];

function displayBdayList(today){
var bday,strList='';
for (var i=0;i<arrBday.length;i++){
bday = new Date(arrBday[i][1]);
if (!isNaN(bday) && bday.getMonth()==today.getMonth() && bday.getDate()==today.getDate())
strList+='- '+arrBday[i][0]+" ("+(today.getFullYear()-bday.getFullYear())+")<br>";
}
if (strList=='') strList='- NONE'
document.write("<h4>Today's Birtdays:</h4>"+strList)
}

displayBdayList(new Date());
</script>



this is birth day script so,i want in this script if "Bob"birday then a web link is automatic open like Link''http://forums.htmlhelp.com''



please help
CharlesEF
You should not use 'document.write'. Instead, try this:
CODE
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="author" content="Charles E. Finkenbiner - Creative Electronic Formulas, Inc.">
<meta name="generator" content="SynWrite 6.22.2280">
<title>Birthday Sample</title>
<script type="text/javascript">
var arrBday = [
                ['Bob','11/23/1973'],
                ['Peter','12/2/1977'],
                ['John','12/2/1999'],
               ];

function displayBdayList(today)
{
var bday,strList='';
for(var i = 0; i < arrBday.length; i++)
{
  bday = new Date(arrBday[i][1]);
  if(!isNaN(bday) && bday.getMonth()==today.getMonth() && bday.getDate()==today.getDate())
  strList += '- ' + arrBday[i][0] + " (" + (today.getFullYear() - bday.getFullYear()) + ")<br>";
}
if(strList == '') strList = '- NONE'
document.getElementById("bday").innerHTML = "<h4>Today's Birtdays:</h4>"+strList;
}
</script>
</head>
<body>
<div id="bday"></div>
<script type="text/javascript">
window.onload=function()
{
  displayBdayList(new Date());
}
</script>
</body>
</html>
Christian J
QUOTE(CharlesEF @ Dec 3 2016, 12:20 AM) *

CODE

<div id="bday"></div>
<script type="text/javascript">
window.onload=function()
{
  displayBdayList(new Date());
}
</script>
</body>
</html>


Can't resist a few nitpicks. tongue.gif First, since the

CODE
displayBdayList(new Date());

function call is located after

CODE
<div id="bday"></div>

you don't need any load event, you can simply call the function right away.

If OTOH the function call is not loacted after the DIV you do need some load event, but then the page becomes more portable if you use addEventListener instead of window.onload, since you can use multiple addEventListener loads without conflicts (you can only use a single window.onload on a page).

Finally, it's better to use the DOMContentLoaded event instead of onload, since the former fires as soon as the HTML has loaded (while the latter waits for images etc).


CharlesEF
Since I don't know what the rest of the page looks like I choose to use the method I posted. Otherwise, I agree with everything you stated. If the OP returns with more information then we can refine the code.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.