Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (hitaro9):

Simple Javascript + Html help please?

OpenStudy (hitaro9):

Hey, in my html file I have this: Birthday: <input type="date" id="bDate"/> <br/>

OpenStudy (hitaro9):

and in my javascript file, I have this: var birthIn = document.getElementById("bDate").value; var dateParts = birthIn.split('-'); var yearIn = dateParts[3];

OpenStudy (hitaro9):

Now, whenever I try to get the year out of the yearIn variable, it gives not a number. My method works fine for the day and month, I can get those no problem, but the 3rd part of the array isn't working. Help please?

OpenStudy (anonymous):

If it's giving you "not a number", what is it giving you? Just from looking at this quickly, I would say that maybe you are trying to get the year from an array index that doesn't exist. If your date is "01-10-1999" and you are splitting this on the '-' character, you will be adding 3 objects to your array. [0] = month; [1] = day; [2] = year; So, I would try changing the following: var yearIn = dateParts[3]; to: var yearIn = dateParts[2]; and see if that works.

OpenStudy (hitaro9):

Appreciate the help. ^.^

OpenStudy (anonymous):

Anytime.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!