This is what I am trying to do. Three select drop downs (year, month, day). The user will select year, then month, and the JavaScript will populate the day with the correct number of days for that month/year.

I have a javascript function to find the number of days in that month/year selection. I am using onChange on the month field, but here is where i am running into the problem. I can't for the life of me remember the way to send the values for the year and the month to the function. I have done it before but that code is saved at my office state side.

Code:

	Birthday
	<br>
	Year: 
	<select name="year">
		<option value="NULL">Select 1st
		<?php
			$year = $date[year];
			$eyear = $year - 17;
			$oyear = $eyear - 100;
			while ($eyear >= $oyear)
			{
				print "<OPTION VALUE=\"" . $eyear . "\">" . $eyear . "\n		";
				$eyear--; 
			}
		?>
	</select>
	&nbsp;&nbsp;&nbsp;
	Month:
	<select name="month" onchange="getDate(this.value);">
		<option value="NULL">Select 2nd
		<option value="00">January
		<option value="01">February
		<option value="02">March
		<option value="03">April
		<option value="04">May
		<option value="05">June
		<option value="06">July
		<option value="07">August
		<option value="08">September
		<option value="09">October
		<option value="10">November
		<option value="11">December
	</select>
	&nbsp;&nbsp;&nbsp;
	Day:
	<select name="day">

</select>

// Runs month and year to get the days in that motnh for that year
function getDate(year, month)
{
var over = 32 - new Date(year, month, 32).getDate();
var day = new Array();
var count = 0;
while (over>0)
{
day[count] = over;
over = over - 1;
count = count - 1;
}
}

    I think that will work

    print "<OPTION VALUE='$eyear' >$eyear</option>";
    
      reddrum wrote:

      I think that will work

      print "<OPTION VALUE='$eyear' >$eyear</option>";
      

      I guess I should have been more specific. The problem lies within this line of code.

      <select name="month" onchange="getDate(this.value);">

      The site I am working on requires the user to be 18 or older. The PHP code you mentioned is a loop to display from 17 year ago, to 106 years ago as an option for the year. I put it in a PHP loop so the year will always change on the first of the year, this will prevent me from adding 1992 next year to the options.

      The problem is the part above, getDate(this.value); runs the getDate function. It will pass the value selected from month because that is where the onchange is located and it has the this.value. I need to find the code equivalent to this.value that pulls the value from another section of the form specifically the year. I hope this clarifies my problem.

        Ok I figured it out, my script is not done I will post it when I finish. Here is the line to submit more than one value to a function from a HTML form.

        <select name="month" onchange="getDate(this.value, document.input.year.options[document.input.year.selectedIndex].value);">
        

        This is the format document.FORMNAME.DESIREDVALUE.options[document.FORMNAME.DESIREDVALUE.selectedIndex].value

        Hope this will help others, when and if they run into the same problem I had.

          Write a Reply...