Simple Javascript + Html help please?
Hey, in my html file I have this: Birthday: <input type="date" id="bDate"/> <br/>
and in my javascript file, I have this: var birthIn = document.getElementById("bDate").value; var dateParts = birthIn.split('-'); var yearIn = dateParts[3];
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?
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.
Appreciate the help. ^.^
Anytime.
Join our real-time social learning platform and learn together with your friends!