Jump to content

Repopulating a Select with number of days in a month


Kurrel

Recommended Posts

Hi everyone,

 

I am writing a birthday input for a user management system.  At this point in time the code looks like this

 

print("<select style='width:40%;'>");
				for ($day=1; $day < 32; $day++) {
					print("<option>");
					print($day);
					print("</option>");
				}
				print("</select>");

				print("<select style='width:60%;'>");
				for ($month=1; $month < 13; $month++) {
					print("<option>");
					print(date("F", mktime(0, 0, 0, $month, 01, 2000)));
					print("</option>");
				}
				print("</select>");

 

I don't like having the full 31 days for every month, including February and 30 day months.  I am trying to develop an onchange for the month select that will repopulate the day select but can't find javascript functions that can (a) depopulate elements from a select and (b) insert elements into a select.

 

So far, I've managed to get a hack by creating strings $28day, $30day and $31day of hardcoded text

'<select><option>1</option>...</select>

and replacing as needs, but it seems a truly clumsy and laborious workaround.  Can anyone point me to commands for manipulating selects or to a cleaner workaround?

 

~Kurrel

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.