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.

Edited by jonsan32

4 Years
Discussion Span
Last Post by EvolutionFallen

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" />
<input type="submit" id="getGradYear" onclick="expectedGradYear(); return false;" />

<script type="text/javascript">
function expectedGradYear() {

    currGrade = document.getElementById('currentGrade').value;

    // Make sure we're dealing with a number from 1(?)-12
    currGrade = parseInt(currGrade, 10);
    if(currGrade < 1 || currGrade > 12) {
        // Do your error handling
        alert("invalid range");
        return false;

    var MAX_GRADE = 12;

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

    var gradYear = currYear + (MAX_GRADE - currGrade);  

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

    document.getElementById('ElementYouWantToUpdate').innerHTML = gradYear;

    return false;   

~ EF

Edited by EvolutionFallen: Added HTML fields and slight modification to JS


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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.