...

View Full Version : How to send a form result as a url parameter "onclick"??



Baseball
01-25-2012, 05:10 PM
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:thumbsup:!





<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>

Baseball
01-26-2012, 02:21 AM
possibly with Querystring.js?

Old Pedant
01-26-2012, 03:43 AM
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?

Old Pedant
01-26-2012, 03:44 AM
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?

Baseball
01-26-2012, 04:11 AM
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.html?TEAM_ID=TS63464122&LOG_IN_ID=11111111&league_age=[result]&PLAYER_NAME=[result]

Old Pedant
01-26-2012, 04:56 AM
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?

Old Pedant
01-26-2012, 05:18 AM
Here, something like this (tested and working):


<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.

Baseball
01-26-2012, 05:37 AM
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?

Baseball
01-26-2012, 06:50 AM
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.




<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>

Baseball
01-26-2012, 10:21 PM
?Can anyone help? with these last few items

Old Pedant
01-27-2012, 01:18 AM
Here's how I do generic query string processing in JavaScript:


<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"];
...

Old Pedant
01-27-2012, 01:19 AM
You have some illegal HTML there.

Just for starters, you have two <html> and two <head> tags.

Baseball
01-27-2012, 01:33 AM
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>

Old Pedant
01-27-2012, 01:44 AM
Okay...try this...


<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.

Baseball
01-27-2012, 01:46 AM
The date range for if is [division].

the above code did not work?

http://ntsacom.homestead.com/calculator-TEST1.html?team_id=12345

Old Pedant
01-27-2012, 01:48 AM
Note that the INCOMING query string is *NOT* case sensitive. I convert all names in the name=value pairs to lower case.

So, for example, in testing this I named *MY* page "baseball.html" and then I used a URL like this:


http://localhost/testing/baseball.html?team_id=7173&division=331&LOG_IN_ID=meandme

And, indeed, those team_id, division, and log_in_id values appeared on your test page when the form was submitted:


http://ntsacom.homestead.com/TEST3.html?TEAM_ID=7173&LOG_IN_ID=meandme&DIVISION=331&PLAYER_NAME=Timmy+Smith&league_age=9

See? All the values passed along correctly.

Old Pedant
01-27-2012, 01:49 AM
I added the form fields but no parameters are passed?


<br>
Team ID: <input name="TEAM_ID" /><br/>
Login ID: <input name="LOG_IN_ID" /><br/>
Division: <input name="DIVISION" /><br/>
<br>

And I pulled them out and made them hidden fields.

And the values won't pass automatically. See the tail end of my "validateSend" function.

Baseball
01-27-2012, 01:52 AM
I know this is like talking politics with a monkey, than you for you patience.

Old Pedant
01-27-2012, 01:53 AM
The date range for if is [division].

the above code did not work?

http://ntsacom.homestead.com/calculator-TEST1.html?team_id=12345

HUH? Worked fine for me.

It submitted to your TEST3 page as

http://ntsacom.homestead.com/TEST3.html?TEAM_ID=12345&LOG_IN_ID=undefined&DIVISION=undefined&PLAYER_NAME=asdf+asdf&league_age=9

Because you didn't have a log_in_id or division in the first URL, there was nothing to pass on to the TEST3 page. So those get "undefined".

Old Pedant
01-27-2012, 01:54 AM
The date range for if is [division].


And what is that supposed to mean? Give me some examples.

Baseball
01-27-2012, 02:03 AM
YES! your are very correct!

the only part left is the if,

Division is the age of the team. example division=8 for an 8 year old team.


"if league_age<division then the player is to old.

Kids "league_age"=9
Teams "division"=8
the player is too old

Kids "league_age"=9
Teams "division"=9
that is ok

Kids "league_age"=9
Teams "division"=10
that is ok



all else is working great!!!!!

Old Pedant
01-27-2012, 02:16 AM
And what about

Kids "league_age"=6
Teams "division"=10

Surely that's not okay?

What's the range? Best answer: Show all possible divisions.

Baseball
01-27-2012, 02:20 AM
yes-

a player can play up 2 age divisions above his age.

8u can play 10u but not 11u



must be 5 to play and no older than 18

5 can play ..5, 6 or 7
6...............6, 7, 8
7...............7, 8, 9
8...............8,9,10
9...............9, 10, 11
10.............10, 11, 12
11.............11, 12, 13
12.............12, 13, 14
13.............13, 14, 15
14.............14, 15, 16
15.............15, 16, 17
16.............16, 17, 18
17.............17, 18
18.............18

Old Pedant
01-27-2012, 02:27 AM
*SIGH*

But I don't know what *ALL* the divisions *ARE*.

If you don't tell me that, I can't give the answer.

Are you saying there is an age division for each and every age????

5u, 6u, 7u, 8u, 9u, 10u, 11u, 12u,....,18u ???

Surely that's not correct. It's been about 25 years since my son was in Little League, and I know his league didn't have a division for every year.

Suppose you have 8u, 11u, 15u, 18u. So "two divisions above his age" would mean that an 8 year old could play 15u. *THAT* is "two division" (not two years...but you didn't say years) above his age.

More precision, please.

Baseball
01-27-2012, 02:34 AM
our divisions of play are-
6u
7u
8u
9u
10u
11u
12u
13u
14u
15u
16u
17u
18u

there are enough kids playing to support age specific now. I know, we played
7/8
9/10
11/12
13/14/15 and up when I played.

Old Pedant
01-27-2012, 03:01 AM
Well, I will be darned. Never expected that answer!

Okay, then it's easy.



// 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 -- };

if ( league_age < 5 || league_age > 18 )
{
alert("Sorry, but that player is league age " + league_age
+ "\nPlayers must be 5 through 18 to play.");
return;
}

var division = parseInt( qs["division"] );
if ( league_age < division-2 )
{
alert("Sorry, but that player is league age " + league_age
+ "\nand is too young to play in division " + division + "u.");
return;
}
if ( league_age > division )
{
alert("Sorry, but that player is league age " + league_age
+ "\nand is too old to play in division " + division + "u.");
return;
}

// 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";
}

New code is in red. Rest of code remains unchanged.

It should work regardless of whether the division in the query string is
&division=10
or
&division=10u
or
&division=10under

If you need it to handle something like "under10" then we need to change the code a little.

Baseball
01-27-2012, 03:20 AM
I'M SMILING LIKE A CHESHIRE CAT!!

I'm new here, how do I thank you, show appreciation??

Where are you located? state??

Old Pedant
01-27-2012, 03:30 AM
You already thanked the post, that's enough.

Seattle, WA, area.

(We still have snow on the ground from last Tuesday's storm! 9 days now.)

Baseball
01-27-2012, 06:12 PM
Well thank you again. It works great. I am working on getting the "if" to work after the first submission though. You have to refresh the page when it returns you to the app after form submission. Sure its something little.

Im in Texas....70's this last week!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum