The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Birthday script
shammo
post Dec 1 2016, 08:26 AM
Post #1





Group: Members
Posts: 1
Joined: 1-December 16
Member No.: 24,948



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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Dec 2 2016, 06:20 PM
Post #2


This is My Life
*******

Group: Members
Posts: 1,408
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



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>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Dec 4 2016, 01:51 PM
Post #3


.
********

Group: WDG Moderators
Posts: 7,615
Joined: 10-August 06
Member No.: 7



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


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Dec 4 2016, 06:18 PM
Post #4


This is My Life
*******

Group: Members
Posts: 1,408
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 20th August 2017 - 12:23 PM