I have a site for youth basketball, where parents can list their kid to get them onto a team. The listings that get replied to by teams needing players are deleted, but some listing remain on there for months or years. To combat the potential confusion of which grade a kid is currently in, I have them list the kid's graduation year instead. Some parents, however, struggle mightely in figuring out the simple math in that.

I want to put a textbox on top of the page that they can enter their kid's current grade, then have the output be the kid's graduation year (barring any flunking, of course). I'm also wondering if there's any way to incorporate the passing of time into the script, so that nothing needs to be changed from year to year. I'm thinking that with the school year ranging from September to May, that a formula might be something like this:

12 - (grade level entered) + (current year) + 1 [adding one only if the current day is between May and December]

but how can I make that into a table with javascript? Btw, I realize that even my formula may be wrong. Feel free to correct it.

ANY help is heavily appreciated.

All 8 Replies

Not sure what you mean regarding outputting a table, I don't know what the contents for your table are or where you're grabbing them from. The following script should help you get the expected graduation year with JS, though:

``````<input type="text" id="currentGrade" />

<script type="text/javascript">

// Make sure we're dealing with a number from 1(?)-12
return false;
}

var currTime = new Date();
var currYear = currTime.getFullYear();
var currMonth = currTime.getMonth(); // getMonth() returns 0 - 11; 0 = Jan, 1 = Feb, etc.

// Are we in Jun - Dec? (Change based on when classes end at your school)
if(currMonth >= 5 && currMonth <= 11)

return false;
}
</script>
``````

~ EF

That looks great and is exactly what I was talking about. But it doesn't output anything when I am in the range. Am I doing something wrong?

And would it be easier to just do a dropdown list of 1st Grade, 2nd Grade, etc... Then there wouldn't have to be an invalid argument. Let me know, and thank you so much.

I'm curious, why not just mark down the birth date of the person? You can figure out everything you need based off of that, can you not?

Sometimes kids stay back a grade, or get skipped. Youth basketball rules are kinda silly. To me, I never did mind playing against older players. That just helps you get better. But they are so strict on grade level and cut-off dates, n such. I'm kinda dissapointed in the parents who can't just count up to the grad year, to tell you the absolute truth!

You need to modify the element ID on line 29 of my code to indicate where you want the year to appear. So for example, after HTML for the submit you could add:

``````<span id="exp-grad-date"></span>
``````

Then on line 29, change the value in the single quotes to `exp-grad-date`

That is awesomely perfect. Thank you so much. I don't know if I could have done that if I had two lifetimes to live.

No worries, not too tough when you practice it! :)
Please mark the thread as solved if you have no further questions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.