Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTadjiev Codes
9,626 PointsJS form validation Day, Month, Year onChange event according to the month
Hi, Dear folks, Could you please help me out to understand the problem like why my function"monthChanging" doesn't work through onchange embedded event in HTML.
Also function firstName() doesn't work let's say to output the name once onclick button pressed. This is the task I'm trying to do: Birth Month (Dropdown) Provide the months as strings - Birth Date (Dropdown) Provide the number of days relative to that months number of days - Birth Year (Dropdown) Provide the years in order from Higher to lower
When the month is changed: populate the date dropdown, with the correct number of days (for february, you need to check the year dropdown to see if its a leap year) Google the rules for leap year and number of days in the month
With a button click, Output the sentence to the log area With a button click, reset the form to default (empty) The link for the Workspace: https://w.trhou.se/34ofyzzw79 I just need help mostly with the months let's say if its Febraury 28 days and if other 7 months like 31 days shown in the days dropdown. The logic of my function seems to be not bad but how to connect it to another dropdown? LEt's sat if January selected then then days dropdown shows 31 if another month selected 30 if February then 28 days.
4 Answers
Steven Parker
230,879 PointsI see a few issues:
- the arguments passed in are not being used
- a default end date should be established before testing for exceptions
- the element value should be tested with the month instead of the element itself
- the date should be cleared before re-populating
- the wrong months were being tested
- "populateDropDownWithRange" still needs to be called after the end date is determined
function monthChanging(Month, Date) {
//updates the item to empty always
Date.innerHTML = "";
var daysToPossessEnding = 31;
if (Month.value === "April" || Month.value === "June" ||
Month.value === "September" || Month.value === "November") {
daysToPossessEnding = 30;
} else if (Month.value === "February") {
daysToPossessEnding = 28;
}
populateDropDownWithRange(1, daysToPossessEnding, Date);
}
And there's no code for determining a leap year, you'll still need to add that.
Liam Clarke
19,938 PointsHello
What is it your trying to do? I don't understand what you are needing.
As for why the monthChanging()
doesnt work, this is because the first parameter is not defined, monthChanging(month, this.value)
, month.
Can you please provide some more info as to what your expected result is?
Thank,
Tadjiev Codes
9,626 PointsHi Mr.Liam, I hope you're doing well) I'm looking for the days dropdown like 30 31 28 change according to the month. LEt's say I selected February so I want to have 28 days. If selected January then 31 days. I wanna add the Leap year function as well. And then output the result on the div. LEt's say First name: Andrew Lstname MCcebe and Born in 1990 and 30 October for Example. Thanks
Tadjiev Codes
9,626 PointsSteven Parker
KRIS NIKOLAISEN
CAN YOU PLEASE HELP ME PLEASE? YOU'RE THE ONLY 2 FOLKS WHO GIVE SUPER HELPFUL RESPONSES)
Tadjiev Codes
9,626 PointsAlrighty, Thank you very much. You really helped me out to understand this issue with this code)) Super helpful explanation)
Tadjiev Codes
9,626 PointsTadjiev Codes
9,626 PointsThanks a lot, Mr.Steven)))
I don't understand one thing from the code how the parameter Month check the values of the months like Month.value? Where it is exactly connected to the Month dropdown list? And calling the function
populateDropDownWithRange(1, daysToPossessEnding, Date);
connects it to that drop down starting number given 1, ending number 31 through a variable and theElement is the Date. Thanks
Steven Parker
230,879 PointsSteven Parker
230,879 PointsThe parameter "Month" represents the argument "birthMonthSelector" used when the function is called from the HTML:
<select id="ddBirthMonths" onchange="monthChanging(birthMonthSelector,birthDAteSelector)">
This same call connects "Date" to "birthDAteSelector".