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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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