Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Detect Creation of Dropdown List?


Message #1 by "Ray Murphy" <raymurphy@g...> on Tue, 7 May 2002 18:58:41
Gerald,

>So how did you populate that cbobox on the fly?

The javascript code to populate the cbobox on the fly is as follows :

<SCRIPT LANGUAGE="JavaScript">

function build_years_list()
{
	var thisYear, i

	// get current date
	date=new Date()	
	
	// year 2000 problem in old versions of netscape
             // (Netscape returns 101 for the year 2001)
	if(date.getYear()<1000)
	{
		thisYear = date.getYear() + 1900;
	} else {
		thisYear = date.getYear();
	}

	// write beginning of year-combo
	document.write('<select name=\"YearDropDown\">')

	// loop through each year, but the latest year MUST be
	// 18 years to the calendar year to reflect the fact 
	// that applicants must be 18 years old.
	for(i=1901;i<=thisYear - 18;i++) {
	
		document.write('<option value=\"' + i + '\">' + i
                      +'</option>')
	}

	// have now got all the years, so close the SELECT tag
	document.write('</select>') 
}

</SCRIPT>

Then in amongst your normal html code, where you want the dropdown list of 
years to appear :

<SCRIPT language="JavaScript">
        build_years_list();
</SCRIPT>


Regards.

Ray


  Return to Index