Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to send a form result as a url parameter "onclick"??

    This is a form to calculate a players age as of May 1st of each year. I need to send the result in a URL string to
    "http://ntsacom.homestead.com/TEST3.html?TEAM_ID=TS63464122&LOG_IN_ID=11111111&league_age=[FORM RESULT]
    Can anyone help. This to complete a roster app for our youth BASEBALL league. My JavaScript is very limited and the gentleman that was working on this has abandoned it after receiving pay for the project (lesson learned). I have enough knowledge to finish the project once we figure this one small piece out. Thank you for looking at this for me!


    Code:
    <p id="form"></p>
    <form id="get_birthday" name="get_birthday">
    
    <select id="form_get_month" name="form_birth_month">
    <option value="0">january</option>
    <option value="1">february</option>
    <option value="2">march</option>
    <option value="3">april</option>
    <option value="4">may</option>
    <option value="5">june</option>
    <option value="6">july</option>
    <option value="7">august</option>
    <option value="8">september</option>
    <option value="9">october</option>
    <option value="10">november</option>
    <option value="11">december</option>
    </select>
    
    
    
    
    <select id="form_birth_day" name="form_birth_day">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
    </select>
    
    
    
    
    <select id="form_get_year" name="form_birth_year">
    <option value="2011">2011</option>
    <option value="2010">2010</option>
    <option value="2009">2009</option>
    <option value="2008">2008</option>
    <option value="2007">2007</option>
    <option value="2006">2006</option>
    <option value="2005">2005</option>
    <option value="2004">2004</option>
    <option value="2003">2003</option>
    <option value="2002">2002</option>
    <option value="2001">2001</option>
    <option value="2000">2000</option>
    <option value="1999">1999</option>
    <option value="1998">1998</option>
    <option value="1997">1997</option>
    <option value="1996">1996</option>
    <option value="1995">1995</option>
    <option value="1994">1994</option>
    <option value="1993">1993</option>
    </select> 
    
    
    
    
    <input onclick="calculate_age();" type="button" value="submit " />
    </form>
    
    
    
    
     <-------------$ I want this to pass as a URL parameter "onclick" of the above button -------------->
    <p id="baseball">
    
    
    
    
    
    <script language="JavaScript">
    <!-- hide script from old browsers -->
    
    function calculate_age()
    {
    var birth_year =  window.document.get_birthday.form_birth_year.value;
    var birth_month = window.document.get_birthday.form_birth_month.value;
    var birth_day = window.document.get_birthday.form_birth_day.value;
    
    if (((birth_month == 3) || (birth_month ==5) || (birth_month==8) || (birth_month==10)) && (birth_day==31))
    {
    alert("Please check that you entered a valid date")
    return;
    }
    if ((birth_month == 1) && (birth_day >28))
    {
    alert("Please check that you entered a valid date")
    return;
    }
    
    
    //Create the date object for todays date
    var now = new Date();
    
    //Extract the current  year,
    var the_year = now.getFullYear();
    
    // Calculate elegibility for sport
    
    var league_text = ""
    
    
    var paragraph = document.getElementById("baseball");
    
    
    //Clear the contents of paragraph if the submit button has been clicked more than  once .
    //the Firefox way
    if (paragraph.innerText = "");
    else
    //The MSIE way
    if (paragraph.textContent = "");
    
    var league_age = (the_year - birth_year)
    
    
    if (birth_month > 3)
    league_age --;
    
    
    if (league_age < 5 )
    {
    league_text = "1"
    }
    
    if ((league_age > 5) && (league_age <12))
    {
    league_text = "1"
    }
    
    else if ((league_age >12) && (league_age <16))
    {
    league_text = "1"
    }
    
    else if ((league_age >15) && (league_age <19))
    {
    league_text = "1"
    }
    
    else if (league_age > 18)
    {
    league_text = "1"
    }
    
    
    
    var output_text = document.createTextNode(league_text);
    var output_age = document.createTextNode(league_age);
    
    paragraph.appendChild(output_age);
    
    paragraph.appendChild(output_text);
    
    S.redirectTo("search-results?baseball=value1")
    
    
    
    } 
    </script>
    Last edited by Baseball; 01-26-2012 at 04:21 AM.

  • #2
    New Coder
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    possibly with Querystring.js?

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    So if you are passing the data to another page, this page is going to disappear, right?

    So what's the point in dumping the league_age into the <p id="baseball"> when it's only going to be there for a millisecond or so...the human won't even see it.

    Or do you want to show the league_age first, giving the person a chance to make sure it is right before proceeding?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    And are you really concerned with the "how to send the data" part or is it the "how to receive the data" you need help with? Or both?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have a complete registration piece on the next page that is set up to accept the league age parameter. It does not need to be displayed...simply passed on in the URL string. Passing the birth date would be great too. The registration piece will accept parameters but will not calculate the league age. Thank you very much for your time!



    this shows the page its passed to
    http://ntsacom.homestead.com/TEST3.h...11&league_age=[result]&PLAYER_NAME=[result]
    Last edited by Baseball; 01-26-2012 at 04:29 AM.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    Okay, so on this page that calculates the league_age, you really *ALSO* need form fields for TEAM_ID, LOG_IN_ID, and PLAYER_NAME, right?

    And I can trust that your code that is calculating league_age is correct, right?

    The easy way to do this is to simply set up *TWO*<form>s on the page, one that has the dropdowns for picking the birth date, and the other that has the 4 required fields.

    So then your JS code calculates the league_age, drops it into the right spot on the *OTHER* <form>, and submits the other form.

    You need help with that?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    Here, something like this (tested and working):
    Code:
    <html>
    <head>
    <title>Calculate League Age</title>
    <script type="text/javascript">
    function calculate_age()
    {
        var bform = document.getElementById("get_birthday");
        var birth_year = parseInt(bform.form_birth_year.value);
        var birth_month = parseInt(bform.form_birth_month.value);
        var birth_day = parseInt(bform.form_birth_day.value);
    
        var birthDate = new Date( birth_year, birth_month, birth_day );
        if ( birthDate.getMonth() != birth_month ) 
        {
            alert("YOu entered and invalid day for that year and month");
            return;
        }
        //Create the date object for todays date
        var now = new Date();
    
        //Extract the current  year,
        var the_year = now.getFullYear();
    
        // Calculate elegibility for sport
        var league_text = ""
    
        var league_age = (the_year - birth_year)
        if (birth_month > 3) { league_age -- };
    
        // WHAT IS THE POINT OF ALL THIS STUFF?
        // AND WHAT HAPPENS IF THE league_age is EXACTLY 5???  You have no test for that
        if (league_age < 5 ) { league_text = "1"; }
        if ((league_age > 5) && (league_age <12)) { league_text = "1"; }
        else if ((league_age >12) && (league_age <16)) { league_text = "1"; }
        else if ((league_age >15) && (league_age <19)) { league_text = "1"; }
        else if (league_age > 18) { league_text = "1"; }
    
        document.getElementById("sendit").league_age.value = league_age;
        document.getElementById("age").style.visibility = "visible";
    } 
    </script>
    </head>
    
    <body>
    Please enter the following information:
    <form id="sendit" action="http://ntsacom.homestead.com/TEST3.html" method="get">
    Team ID: <input name="TEAM_ID" /><br/>
    Player Name: <input name="PLAYER_NAME" /><br/>
    Login ID: <input name="LOG_IN_ID" /><br/>
    After you fill in the birth date information, the league age will show:<br/>
    <div id="age" style="visibility: hidden;">
    League Age: <input name="league_age" readonly />
    </div>
    <input type="submit" value="Submit this player" />
    </form>
    <hr>
    Please enter this player's birth date:<br/>
    <form id="get_birthday">
    Month: <select id="form_get_month" name="form_birth_month">
    <option value="0">january</option>
    <option value="1">february</option>
    <option value="2">march</option>
    <option value="3">april</option>
    <option value="4">may</option>
    <option value="5">june</option>
    <option value="6">july</option>
    <option value="7">august</option>
    <option value="8">september</option>
    <option value="9">october</option>
    <option value="10">november</option>
    <option value="11">december</option>
    </select>
    Day: <select name="form_birth_day">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
    </select>
    Year: <select name="form_birth_year">
    <option value="2011">2011</option>
    <option value="2010">2010</option>
    <option value="2009">2009</option>
    <option value="2008">2008</option>
    <option value="2007">2007</option>
    <option value="2006">2006</option>
    <option value="2005">2005</option>
    <option value="2004">2004</option>
    <option value="2003">2003</option>
    <option value="2002">2002</option>
    <option value="2001">2001</option>
    <option value="2000">2000</option>
    <option value="1999">1999</option>
    <option value="1998">1998</option>
    <option value="1997">1997</option>
    <option value="1996">1996</option>
    <option value="1995">1995</option>
    <option value="1994">1994</option>
    <option value="1993">1993</option>
    </select> 
    <br/>
    Click here to calculate league age:
    <input onclick="calculate_age();" type="button" value="Calculate" />
    </form>
    
    </body>
    </html>
    Explain what the purpose of "league_text" is and what it really should be and we could maybe fix it, too.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New Coder
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The team ID and login are passed from the login page that is prior to the form submission.

    The coach logs into a "Team back office area with login ID and a password. Those 2 parameters are set to pass as parameters onto the next page. I was hoping to make those hidden fields ( I think they will pass due to another app on the same page that is set to pass them also). Is there a way to input the Players name and birth date and click submit? Without manually clicking calculate?

    The league text was supposed to do the "if" part. If Bobby is 10u and the team is a 9u team, then the coach would see [league text] "player is to old"...but that is way out of my league.

    Thank you very much for your help, this is a blessing!

    Also, how would I use "return validate(FormName)", for league age and player name?
    Last edited by Baseball; 01-26-2012 at 05:56 AM.

  • #9
    New Coder
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    WOW!, this is great. I moved a few of the forms around to meet needs. Still worked great!
    The only thing left is...

    **The 'if' in the league text...

    if (league_age < division ) { league_text = "YOUR PLAYER IS TO OLD FOR THIS TEAM!"; }

    **Form values [team_id], [password] and [division] will be passed to this from from the login form. Cant figure out how to get the forms to receive the parameters in the Url string that comes to this page.

    **Validate the Player_name and league_age values are not empty upon submission

    Thank you.


    Code:
    <html>
            <head>
                    <html>
                          <head>
                              <title>Calculate League Age</title>
                                 <script type="text/javascript">
                                    function calculate_age()
                                    {
                                    var bform = document.getElementById("get_birthday");
                                    var birth_year = parseInt(bform.form_birth_year.value);
                                    var birth_month = parseInt(bform.form_birth_month.value);
                                    var birth_day = parseInt(bform.form_birth_day.value);
    
                                    var birthDate = new Date( birth_year, birth_month, birth_day );
                                    if ( birthDate.getMonth() != birth_month ) 
                                    {
                                    alert("YOu entered and invalid day for that year and month");
                                    return;
                                    }
                                    //Create the date object for todays date
                                   var now = new Date();
    
                                    //Extract the current  year,
                                    var the_year = now.getFullYear();
    
                                   // Calculate elegibility for sport
                                   var league_text = ""
    
                                   var league_age = (the_year - birth_year)
                                   if (birth_month > 3) { league_age -- };
    
    
                                  document.getElementById("sendit").league_age.value = league_age;
                                  document.getElementById("age").style.visibility = "visible";
                                  } 
                             </script>
                      </head>
                      <hr>
    
    
                                          Please enter this player's birth date:<br/>
                                          <form id="get_birthday">
                                          Month: <select id="form_get_month" name="form_birth_month">
    <option value="0">january</option>
    <option value="1">february</option>
    <option value="2">march</option>
    <option value="3">april</option>  
    <option value="4">may</option>
    <option value="5">june</option>
    <option value="6">july</option>
    <option value="7">august</option>
    <option value="8">september</option>
    <option value="9">october</option>
    <option value="10">november</option>
    <option value="11">december</option>
                                            </select>
                                                  Day: <select name="form_birth_day">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
                                                </select>
                                                    Year: <select name="form_birth_year">
    <option value="2011">2011</option>
    <option value="2010">2010</option>
    <option value="2009">2009</option>
    <option value="2008">2008</option>
    <option value="2007">2007</option>
    <option value="2006">2006</option>
    <option value="2005">2005</option>
    <option value="2004">2004</option>
    <option value="2003">2003</option>
    <option value="2002">2002</option>
    <option value="2001">2001</option>
    <option value="2000">2000</option>
    <option value="1999">1999</option>
    <option value="1998">1998</option>
    <option value="1997">1997</option>
    <option value="1996">1996</option>
    <option value="1995">1995</option>
    <option value="1994">1994</option>
    <option value="1993">1993</option>
                                                </select> 
                                                        <br/>
                                                              Click here to calculate league age:
                                                              <input onclick="calculate_age();" type="button" value="Validate players age first" />
                                     </form>
                                     <br>
                                     <body>
    
                                     //These values will be passed to THIS form via a Url string.
                                     //Can the values be hidden? or just have a white text color?
                                     <br>
                                                               Team ID: <input name="TEAM_ID" /><br/>
                                                               Login ID: <input name="LOG_IN_ID" /><br/>
                                                               Division: <input name="DIVISION" /><br/>
                                      <br>
                                      <br>
    
    
    
                                     //I need to validate that these form values are not blank prior to submission of the form
                                    <form id="sendit" action="http://ntsacom.homestead.com/TEST3.html" method="get">
                                    Player Name: <input name="PLAYER_NAME" />
                                    <br/>
                                    <br/>
                                                                <div id="age" style="visibility: hidden;">
                                                                League Age:<input name="league_age" readonly />
                                                                </div>
                                                                <input type="submit" value="Submit this player" />
    
    
                                      </form>
    
                           </body>
    </html>
    Last edited by Baseball; 01-26-2012 at 04:14 PM. Reason: comment was no longer valid

  • #10
    New Coder
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ?Can anyone help? with these last few items

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    Here's how I do generic query string processing in JavaScript:
    Code:
    <script type="text/javascript">
    var qs = [ ];
    
    // see if there *IS* a querystring (the stuff after the ? in the URL)
    if ( location.search.length > 1 )
    {
        // yes...so find all the name=value&name=value&name=value pair in query string
        var pairs = location.search.substring(1).split("&");
        // and process one at a time
        for ( var p = 0; p <pairs.length; ++p )
        {
            // split each name=value on the =
            var pair = pairs[p].split("=");
            // so the name is the key and the value gets decoded
            qs[ pair[0].toLowerCase() ] = decodeURIComponent( pair[1] );
        }
    }
    // so at this point, you can find the value of any name from the querystring by doing this
    // (example only)
    var team_id = qs["team_id"];
    var password = qs["password"];
    var division = qs["division"];
    ...
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    You have some illegal HTML there.

    Just for starters, you have two <html> and two <head> tags.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #13
    New Coder
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ok, how do I know if it worked?


    <html>
    <head>
    <title>Calculate League Age</title>
    <script type="text/javascript">
    function calculate_age()
    {
    var bform = document.getElementById("get_birthday");
    var birth_year = parseInt(bform.form_birth_year.value);
    var birth_month = parseInt(bform.form_birth_month.value);
    var birth_day = parseInt(bform.form_birth_day.value);

    var birthDate = new Date( birth_year, birth_month, birth_day );
    if ( birthDate.getMonth() != birth_month )
    {
    alert("YOu entered and invalid day for that year and month");
    return;
    }
    //Create the date object for todays date
    var now = new Date();

    //Extract the current year,
    var the_year = now.getFullYear();

    // Calculate elegibility for sport
    var league_text = ""

    var league_age = (the_year - birth_year)
    if (birth_month > 3) { league_age -- };

    // WHAT IS THE POINT OF ALL THIS STUFF?
    // AND WHAT HAPPENS IF THE league_age is EXACTLY 5??? You have no test for that
    if (league_age < 5 ) { league_text = "1"; }
    if ((league_age > 5) && (league_age <12)) { league_text = "1"; }
    else if ((league_age >12) && (league_age <16)) { league_text = "1"; }
    else if ((league_age >15) && (league_age <19)) { league_text = "1"; }
    else if (league_age > 18) { league_text = "1"; }

    document.getElementById("sendit").league_age.value = league_age;
    document.getElementById("age").style.visibility = "visible";
    }
    </script>
    </head>


    <hr>
    Please enter this player's birth date:<br/>
    <form id="get_birthday">
    Month: <select id="form_get_month" name="form_birth_month">
    <option value="0">january</option>
    <option value="1">february</option>
    <option value="2">march</option>
    <option value="3">april</option>
    <option value="4">may</option>
    <option value="5">june</option>
    <option value="6">july</option>
    <option value="7">august</option>
    <option value="8">september</option>
    <option value="9">october</option>
    <option value="10">november</option>
    <option value="11">december</option>
    </select>
    Day: <select name="form_birth_day">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
    </select>
    Year: <select name="form_birth_year">
    <option value="2011">2011</option>
    <option value="2010">2010</option>
    <option value="2009">2009</option>
    <option value="2008">2008</option>
    <option value="2007">2007</option>
    <option value="2006">2006</option>
    <option value="2005">2005</option>
    <option value="2004">2004</option>
    <option value="2003">2003</option>
    <option value="2002">2002</option>
    <option value="2001">2001</option>
    <option value="2000">2000</option>
    <option value="1999">1999</option>
    <option value="1998">1998</option>
    <option value="1997">1997</option>
    <option value="1996">1996</option>
    <option value="1995">1995</option>
    <option value="1994">1994</option>
    <option value="1993">1993</option>
    </select>
    <br/>
    Click here to calculate league age:
    <input onclick="calculate_age();" type="button" value="Calculate" />
    </form>

    <body>

    <script type="text/javascript">
    var qs = [ ];

    // see if there *IS* a querystring (the stuff after the ? in the URL)
    if ( location.search.length > 1 )
    {
    // yes...so find all the name=value&name=value&name=value pair in query string
    var pairs = location.search.substring(1).split("&");
    // and process one at a time
    for ( var p = 0; p <pairs.length; ++p )
    {
    // split each name=value on the =
    var pair = pairs[p].split("=");
    // so the name is the key and the value gets decoded
    qs[ pair[0].toLowerCase() ] = decodeURIComponent( pair[1] );
    }
    }
    // so at this point, you can find the value of any name from the querystring by doing this
    // (example only)
    var team_id = qs["team_id"];
    var password = qs["password"];
    var division = qs["division"];
    </script>

    <form id="sendit" action="http://ntsacom.homestead.com/TEST3.html" method="get">
    Player Name: <input name="PLAYER_NAME" /><br/>

    <br/>
    <div id="age" style="visibility: hidden;">
    League Age: <input name="league_age" readonly />
    </div>
    <input type="submit" value="Submit this player" />

    </form>

    </body>
    </html>
    Last edited by Baseball; 01-27-2012 at 01:41 AM.

  • #14
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    Okay...try this...
    Code:
    <html>
    <head>
    <title>Calculate League Age</title>
    <script type="text/javascript">
    // setup code that parses the query string and creates lookup table for qs elements
    var qs = [ ];
    
    // see if there *IS* a querystring (the stuff after the ? in the URL)
    if ( location.search.length > 1 )
    {
        // yes...so find all the name=value&name=value&name=value pair in query string
        var pairs = location.search.substring(1).split("&");
        // and process one at a time
        for ( var p = 0; p <pairs.length; ++p )
        {
            // split each name=value on the =
            var pair = pairs[p].split("=");
            // so the name is the key and the value gets decoded
            qs[ pair[0].toLowerCase() ] = decodeURIComponent( pair[1] );
        }
    }
    
    // calculate league_age from birth date information
    function calculate_age()
    {
        var bform = document.getElementById("get_birthday");
        var birth_year = parseInt(bform.form_birth_year.value);
        var birth_month = parseInt(bform.form_birth_month.value);
        var birth_day = parseInt(bform.form_birth_day.value);
    
        var birthDate = new Date( birth_year, birth_month, birth_day );
        if ( birthDate.getMonth() != birth_month ) 
        {
            alert("YOu entered and invalid day for that year and month");
            return;
        }
        //Create the date object for todays date
        var now = new Date();
    
        //Extract the current  year,
        var the_year = now.getFullYear();
    
        // Calculate elegibility for sport
        var league_text = ""
    
        var league_age = (the_year - birth_year)
        if (birth_month > 3) { league_age -- };
    
        // okay...age seems okay...so save it in the form that gets sent to next page
        var sendform = document.getElementById("sendit");
        sendform.league_age.value = league_age;
        // and show the age
        document.getElementById("age").style.visibility = "visible";
    } 
    
    // code to validate the sendit form.
    // if league_age and player name look good, allow send
    // at same time, pass along the values from the query string
    function validateSend( form )
    {
        if ( form.league_age.value == "" ) 
        {
            alert("You must enter the player's birth date first");
            return false;
        }
        var nameRE = /^[a-z]{2,99}\s([a-z]+\s)*[a-z]{3,99}$/i ;
        if ( ! nameRE.test( form.PLAYER_NAME.value ) )
        {
            alert("You must enter first and last name of player, at least");
            return false;
        }
        // okay...so copy in the hidden information and allow the submit:
        form.TEAM_ID.value = qs["team_id"];
        form.LOG_IN_ID.value = qs["log_in_id"];
        form.DIVISION.value = qs["division"];
        
        // do it!
        return true;
    }
    </script>
    </head>
    <hr>
    Please enter this player's birth date:<br/>
    <form id="get_birthday">
    Month: <select id="form_get_month" name="form_birth_month">
    	<option value="0">january</option>
    	<option value="1">february</option>
    	<option value="2">march</option>
    	<option value="3">april</option>  
    	<option value="4">may</option>
    	<option value="5">june</option>
    	<option value="6">july</option>
    	<option value="7">august</option>
    	<option value="8">september</option>
    	<option value="9">october</option>
    	<option value="10">november</option>
    	<option value="11">december</option>
    </select>
    Day: <select name="form_birth_day">
    	<option value="1">1</option>
    	<option value="2">2</option>
    	<option value="3">3</option>
    	<option value="4">4</option>
    	<option value="5">5</option>
    	<option value="6">6</option>
    	<option value="7">7</option>
    	<option value="8">8</option>
    	<option value="9">9</option>
    	<option value="10">10</option>
    	<option value="11">11</option>
    	<option value="12">12</option>
    	<option value="13">13</option>
    	<option value="14">14</option>
    	<option value="15">15</option>
    	<option value="16">16</option>
    	<option value="17">17</option>
    	<option value="18">18</option>
    	<option value="19">19</option>
    	<option value="20">20</option>
    	<option value="21">21</option>
    	<option value="22">22</option>
    	<option value="23">23</option>
    	<option value="24">24</option>
    	<option value="25">25</option>
    	<option value="26">26</option>
    	<option value="27">27</option>
    	<option value="28">28</option>
    	<option value="29">29</option>
    	<option value="30">30</option>
    	<option value="31">31</option>
    </select>
    Year: <select name="form_birth_year">
    	<option value="2011">2011</option>
    	<option value="2010">2010</option>
    	<option value="2009">2009</option>
    	<option value="2008">2008</option>
    	<option value="2007">2007</option>
    	<option value="2006">2006</option>
    	<option value="2005">2005</option>
    	<option value="2004">2004</option>
    	<option value="2003">2003</option>
    	<option value="2002">2002</option>
    	<option value="2001">2001</option>
    	<option value="2000">2000</option>
    	<option value="1999">1999</option>
    	<option value="1998">1998</option>
    	<option value="1997">1997</option>
    	<option value="1996">1996</option>
    	<option value="1995">1995</option>
    	<option value="1994">1994</option>
    	<option value="1993">1993</option>
    </select> 
    <br/>
    Click here to calculate league age:
        <input onclick="calculate_age();" type="button" value="Validate players age first" />
    </form>
    <br>
    <br>
    // need to validate that these form values are not blank prior to submission of the form
    <form id="sendit" action="http://ntsacom.homestead.com/TEST3.html" 
          method="get" onsubmit="return validateSend(this);">
    <input type="hidden" name="TEAM_ID" />
    <input type="hidden" name="LOG_IN_ID" />
    <input type="hidden" name="DIVISION" />
    
    Player Name: <input name="PLAYER_NAME" />
    <br/><br/>
    <div id="age" style="visibility: hidden;">
        League Age:<input name="league_age" readonly />
    </div>
    <input type="submit" value="Submit this player" />
    </form>
    
    </body>
    </html>
    I would help you on the "player is too old for this team", but you aren't passing any information that tells us WHAT the age range for the given team is.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #15
    New Coder
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The date range for if is [division].

    the above code did not work?

    http://ntsacom.homestead.com/calcula...?team_id=12345
    Last edited by Baseball; 01-27-2012 at 01:50 AM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •