• We just launched and are currently in beta. Join us as we build and grow the community.

Date of Birth Counter Using Javascript

Twofor

Decentralized Marketplace Creator
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
123
Likes
199
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
In this chapter, You will learn to make a Date of birth counter into days, hours and time. Just follow the tutorial below and download the source code.

DIRECTIONS

Creating our HTML code

  1. <FORM

    name

    =

    "live"

    >

  2. <BR

    ><BR

    ><BR

    >


  3. <TABLE

    border

    =

    1

    >
  4. <tr

    >
  5. <td

    ><INPUT

    TYPE

    =

    "button"

    NAME

    =

    "start"

    VALUE

    =

    "Start"

    ONCLICK

    =

    "lifetimer(this.form)"

    ></

    td

    >
  6. <td

    ><INPUT

    TYPE

    =

    "reset"

    NAME

    =

    "resetb"

    VALUE

    =

    "Reset Age"

    ></

    td

    >
  7. </

    tr

    >
  8. <tr

    >
  9. <td

    >

    Date of birth:</

    td

    >
  10. <td

    ><INPUT

    TYPE

    =

    "text"

    NAME

    =

    "age"

    VALUE

    =

    ""

    SIZE

    =

    20

    placeholder=

    "January 10, 1994"

    >

    </

    td

    >
  11. </

    tr

    >
  12. <TR

    ><TD

    >

    You are days old:</

    TD

    >

  13. <TD

    >

  14. <INPUT

    TYPE

    =

    "text"

    NAME

    =

    "time1"

    VALUE

    =

    ""

    size

    =

    8

    >

  15. </

    TD

    >

  16. </

    TR

    >

  17. <TR

    ><TD

    >

    Plus hours old:</

    TD

    >

  18. <TD

    >

  19. <INPUT

    TYPE

    =

    "text"

    NAME

    =

    "time2"

    VALUE

    =

    ""

    size

    =

    8

    >

  20. </

    TD

    >

  21. </

    TR

    >

  22. <TR

    ><TD

    >

    Plus minutes old:</

    TD

    >

  23. <TD

    ><INPUT

    TYPE

    =

    "text"

    NAME

    =

    "time3"

    VALUE

    =

    ""

    size

    =

    8

    ></

    TD

    >

  24. </

    TR

    >
  25. </

    TABLE

    >
  26. </

    FORM

    >

Creating our javascript code

  1. <

    SCRIPT LANGUAGE=

    "JAVASCRIPT"

    >
  2. <!--

    hide this

    script tag's contents from old browsers
  3. function lifetimer(){

  4. today = new Date()

  5. BirthDay = new Date(document.live.age.value)

  6. timeold = (today.getTime() - BirthDay.getTime());

  7. sectimeold = timeold / 1000;

  8. secondsold = Math.floor(sectimeold);

  9. msPerDay = 24 * 60 * 60 * 1000 ;

  10. timeold = (today.getTime() - BirthDay.getTime());

  11. e_daysold = timeold / msPerDay;

  12. daysold = Math.floor(e_daysold);

  13. e_hrsold = (e_daysold - daysold)*24;

  14. hrsold = Math.floor(e_hrsold);

  15. minsold = Math.floor((e_hrsold - hrsold)*60);

  16. document.live.time1.value = daysold

  17. document.live.time2.value = hrsold

  18. document.live.time3.value = minsold

  19. window.status = "Well at the moment you are " + secondsold + "............ seconds old.";

  20. timerID = setTimeout("lifetimer()",1000)

  21. }
  22. // -- done hiding from old browsers -->

  23. </script>

You have now created a date counter that counts days, hours and minutes between the date today and the date you entered. For more suggestions and questions feel free to comment below or email me at [email protected]

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

 

452,292

323,341

323,350

Top