Jump to content

Days, Months, Year


KYKK
 Share

Recommended Posts

I want to have a days months year input of drop boxes, so day have option 1 - 30 OR 31 depend on the select month, and it will show instantly on the page...like http://www.w3schools.com/js/tryit.asp?file...yjs_putdropdown it show the option i put in on the text input, but I want to not to be inside a input text boxand then I need it to show 1 - 30 or 31 on the days it change when select months... in the w3school example it put the result in <input type="text" id=favorite size="60">, id=favorite how do I echo it in php, or use it as a variable?

Link to comment
Share on other sites

<input type="text" id="<?php echo $variable; ?>" size="60"> for your php variable option.The example you linked to is Javascript though.If you want the days to change depending on what the month is, then that would be Javascript, if you dont want to refresh the page each time the user changes the month.:)

Link to comment
Share on other sites

Adding options in javascript is trickier than it should be. Experiment with this. It checks out in IE7, FF Safari, and Opera.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"   "http://www.w3.org/TR/html4/strict.dtd"><html>	<head>		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">		<title></title>		<script type="text/javascript">			da = [31,28,31,30,31,30,31,31,30,31,30,31];			function set_days () {				var d;				var date;				var opt_str = "";				var m = Months.options[Months.selectedIndex].value;				var y = Years.options[Years.selectedIndex].value;				if (m != 1) {					d = da[m];				} else {					date = new Date("February 29, " + y);					d = date.getMonth() == 1 ? 29: 28; // IT'S A LEAP YEAR				}				empty_select (Days);				for (var i = 1; i <= d; i++) {					j = i.toString();					insertOption (Days, j, j)				}			}			function insertOption (s, t, v) {				var y = document.createElement('option');				y.text = t;				y.value = v;				try {					s.add (y, null); // standards compliant				} catch (ex) {					s.add (y); // IE only				}			}			function empty_select (s) {				while (s.length > 0) {					s.remove(s.length-1);				}			}			function init () {				Months = document.getElementById("months");				Years = document.getElementById("years");				Days = document.getElementById("days");				Months.onchange = set_days;				Years.onchange = set_days;			}			window.onload = init;		</script>	</head>	<body>		<div>			<select id="months">				<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="days">				<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="years">				<option value="2008">2008</option>				<option value="2009">2009</option>				<option value="2010">2010</option>				<option value="2011">2011</option>				<option value="2012">2012</option>			</select>		</div>	</body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...