Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8881871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:26:13+00:00 2026-06-14T20:26:13+00:00

essentially what I cannot figure out is how to take a Date property of

  • 0

essentially what I cannot figure out is how to take a Date property of an object (birthday – retrieved from a Date type input in the HTML) and use it to add a “days until next birthday” property to the object, for example:

var surnameField,firstNameField,birthdayField, phoneField, addressField, postField, emailField, groupField ;  //Declaring variables for the fields

var Contact = function(surname,firstName,date, phone , address , post, email, group){
    this.surname = surname ;
    this.firstName = firstName ;
    this.birthdayDate = new Date (date) ;
    this.phone = phone;
    this.address= address;
    this.email = email;
    this.post = post;
    this.group = group;

}



var contacts = [];

var getday = function() {

    for (var i= 0, j=contacts.length;i<j;i++){
       var a = contacts[i].birthdayDate.getDate();
        contacts[i].days = a;

    }
}





Contact.prototype.tableRow = function(){
    var tr = "<tr><td>" + this.surname + "</td><td>" + this.firstName + "</td><td>" + this.birthdayDate + "</td><td>" + this.phone + "</td><td>" + this.email +
            "</td><td>" + this.address + "</td><td>" + this.post + "</td><td>" + this.group + "</td></tr>";
    return tr;
}

var addContact = function(surnameField,firstNameField,birthdayField, phoneField, addressField, postField, emailField, groupField ){
        if(surnameField.value){
            a = new Contact(surnameField.value, firstNameField.value,birthdayField.value, phoneField.value, addressField.value, postField.value, emailField.value, groupField.value);
            contacts.push(a);
        }else{ alert("Please complete all fields")}

}

var clearUI = function(){
    var white = "#fff";
    surnameField.value = "";
    surnameField.style.backgroundColor = white;
    firstNameField.value = "";
    firstNameField.style.backgroundColor = white;
    birthdayField.value="";
    birthdayField.style.backgroundColor = white;
    phoneField.value = "";
    phoneField.style.backgroundcolor = white;
    addressField.value = "";
    addressField.style.backgroundcolor = white;
    postField.value = "";
    postField.style.backgroundcolor = white;
    emailField.value = "";
    emailField.style.backgroundcolor = white;
    groupField.value="";
    groupField.style.backgroundcolor = white;
}


var updateList = function(){
    var tableDiv = document.getElementById("table"),
        table = "<table border='2'><thead><th>  Surname  </th><th> First Name</th><th>Date of Birth</th><th>  Phone Number  </th><th>  Email Address </th><th>  Address  </th><th> Postcode  </th><th>Group</th></thead>";

    for (var i= 0, j=contacts.length;i<j;i++){
        var cntct = contacts[i];
        table += cntct.tableRow();
    }
    table +="</table>";
    tableDiv.innerHTML = table;
    //getday();
    saveContacts();

}

var add = function(){
    addContact(surnameField,firstNameField,birthdayField, phoneField, addressField, postField, emailField, groupField);
    clearUI();
    updateList();
};

var saveContacts = function(){
    var cntcts = JSON.stringify(contacts);
    if (cntcts !==""){
        localStorage.contacts = cntcts;
    }else{
        alert("Could not save contacts");
    }
}

var loadContacts = function(){
    var cntcts = "";
    if(localStorage.contacts !== undefined){
        cntcts = localStorage.contacts;
        contacts = JSON.parse(cntcts);
        var proto = new Contact();
        for (var i=0; i<contacts.length; i++){
            var cntct = contacts[i]
            cntct.__proto__ = proto;
        }
    }
}

var clearContacts = function(){
    contacts = [];
    updateList()

}

/*contacts.prototype.isDue = function(){
    var now = new Date();
    if(this.birthday > now){
        return false;
    } else {
        return true;
    }
};*/



window.onload = function(){
    loadContacts();
    updateList();
    surnameField = document.getElementById("surname");
    firstNameField = document.getElementById("firstName")
    birthdayField = document.getElementById("birthday");
    phoneField = document.getElementById("phone");
    addressField = document.getElementById("address");
    postField = document.getElementById("post");
    emailField = document.getElementById("email");
    groupField = document.getElementById("group");
    addButton = document.getElementById("addButton");
    addButton.onclick = add;
    delButton = document.getElementById("delButton");
    delButton.onclick = clearContacts;
    clearUI();
}

What I was attempting to do was to get the Days/Months value from the date object and use it to calculate the days until the next birthday, however everything I have tried seems to not work. getDay() and getMonth() worked in the console, but when implemented I got a “getDay is not at a deinfed method of .birthday” type of error.

So ideally once fixed each object in the array should have a “daysTilBirthday” property.

Any help would be greatly appreciated.

SOLVED

I forgot to add a check to ensure that when the data was reloaded, it was reloaded as a Date, not as a string, e.g.

cntct.birthdayDate = new Date(cntct.birthdayDate);

Thanks for your help anyway!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:26:14+00:00Added an answer on June 14, 2026 at 8:26 pm

    Try birthday.getDate()

    here is the fiddle : http://jsfiddle.net/ZJ6CN/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm feeling silly that I cannot figure this out, but it's really starting to
I cannot for the life of me figure out why this script is not
I cannot for the life of me seem to be able to figure out
Essentially, what I want to do (in DirectX) is to take two partially-transparent images
We have a legacy system that is essentially a glorified telnet interface. We cannot
Hey all. I've been been trying to figure this out for a while now.
I have been attempting to use an android.preference.DialogPreference inflated from XML, but the documentation
Essentially I cannot find documents or resources that explains the procedure of upgrading a
I have this code: Essentially i'm trying to demonstrate the use of the c#
From my understanding you cannot socket a connection between two iPhones (correct me if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.