Results 1 to 2 of 2

Thread: Combining two scripts

  1. #1
    Join Date
    Jan 2015
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Combining two scripts

    Hi, I have two scripts. They count upcoming birthdays.

    The first script checks in a list of dates if there is a match in the next 7 days:

    HTML Code:
    <html>
    <head>
    
    <script type="text/javascript">
    var arrBday = [
    ['24 май', '05/24', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg'],
    ['Másvalaki Kitti', '9/6', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg'],
    ['Mégvalaki Kálmán', '9/1', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg'],
    
      ['John Doe', '05/6', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg'],
      ['John Doe4', '05/25', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg'],
      ['John Doe6', '5/24', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg']
    
    ];
     
    function getBdaysThisWeek(){
      var arrMonth = new Array("Януари", "Февруари", "Март", "Април", "Май", "Юни", "Юли", "Август", "Септември", "Октомври", "Номеври", "Декември");
    var bday, idx;
    var bdayList = new Array();
    var today = new Date();
     
    for (var i=0;i<arrBday.length;i++){
    var bday = new Date(arrBday[i][1] + '/' + today.getFullYear());
    if (isNaN(bday)) continue;
     
    if ( isBdayInRange(bday, 7) ){
    idx = bdayList.length;
    bdayList[idx] = new Object();
    bdayList[idx].name = arrBday[i][0];
    bdayList[idx].bday = bday;
    bdayList[idx].month = arrMonth[bday.getMonth()];
    bdayList[idx].pic = arrBday[i][2];
    }
    }
    if (bdayList.length > 0){ //sort asc by birthdate
    bdayList.sort(
    function(a, b){
    if (a.bday < b.bday) return -1
    if (a.bday > b.bday) return 1;
    return 0;
    }
    );
    }
    return bdayList;
    }
     
    function isBdayInRange(bday, interval){
    //credit for this function goes to:
    //-Rob (@slingfive) Eberhardt, Slingshot Solutions
    //http://slingfive.com/pages/code/jsDate/jsDate.html
     
    var today = new Date();
    today.setHours(0,0,0,0);
    if (bday < today)
    bday.setFullYear(bday.getFullYear() + 1);
     
    var iDiffMS = bday.valueOf() - today.valueOf();
    nDays = parseInt(iDiffMS / 1000 / 60 / 60 / 24);
     
    if(parseInt(nDays) <= parseInt(interval))
    return true;
    else
    return false;
    }
     
    function displayBdayList(){
    var date = new Date().getDate();
    var bdayList = getBdaysThisWeek();
    var len = bdayList.length;
    var s = "<h1>Предстоящи събития:</h1>";
    if (len>0){
    s += '<ul>';
    for (var i=0; i<len; i++){
    //be mindful of the string-line continuation character (\) at the end of the first line
    s += '<li' + ((date == bdayList[i].bday.getDate())?' class="bdayToday"':'')+ '>\
    <img src="' + bdayList[i].pic + '"> ' + '<strong>' + bdayList[i].name + '</strong> – '
    + bdayList[i].month + ' ' + bdayList[i].bday.getDate() + '</li>';
    }
    s += '</ul>';
    }
    else{
    s += "<h5>Няма събития.</h5>";
    }
    document.write(s);
    }
     
     
    </script>
      <style type="text/css">
    body {
    font:14px Verdana;
    }
    .bdayToday {
    color: red;
    }
    </style>
    
    </head>
    <body>
    <script type="text/javascript">displayBdayList();</script>
    </body>
    </html>
    
    The second script calculates how many years are completed for today:
    HTML Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
    var arrBday = [
                    ['Adrian','5/24/1973'],
                    ['Peter','5/24/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 = 'Няма отбелязано събитие'
    document.getElementById("bday").innerHTML = "<h4>НА ДНЕШНАТА ДАТА:</h4>"+strList;
    }
    </script>
    </head>
    <body>
    <div id="bday"></div>
    <script type="text/javascript">
    window.onload=function()
    {
      displayBdayList(new Date());
    }
    </script>
    </body>
    </html>
    Please help me to publish the list of upcoming events, adding to them how old they are.

  2. #2
    Join Date
    Jun 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi there! Can I ask if you have published it? Share your experience, I am just a beginner, so I am here to learn) By the way, I am attending the online course and our lector mentioned a good service for webmasters, where you can get website optimizer report for your project, I find it really useful tool. I haven`t tried it as, I am only working on my project, but I think I will need some services like this to help me fix and optimize the performance of my site. I hope it will help you too.
    Last edited by HenryKay; 06-26-2020 at 12:15 PM.

Similar Threads

  1. Combining scripts :
    By alexandros in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 03-08-2011, 01:11 AM
  2. Combining 2 scripts?
    By habsgirl11 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 12-14-2007, 02:50 PM
  3. need help with combining 2 scripts
    By yonez in forum JavaScript
    Replies: 1
    Last Post: 06-27-2007, 11:40 AM
  4. combining 2 scripts
    By amyth77 in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 12-02-2005, 07:46 AM
  5. Combining Scripts
    By mossawi in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 06-26-2005, 07:35 PM

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
  •