Click here to Skip to main content
15,914,905 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
HTML
<select name="tag">
				<option>Tag:</option>
				<option>1</option>
				<option>2</option>
				<option>3</option>
				<option>4</option>
				<option>5</option>
				<option>6</option>
				<option>7</option>
				<option>8</option>
				<option>9</option>
				<option>10</option>
				<option>11</option>
				<option>12</option>
				<option>13</option>
				<option>14</option>
				<option>15</option>
				<option>16</option>
				<option>17</option>
				<option>18</option>
				<option>19</option>
				<option>20</option>
				<option>21</option>
				<option>22</option>
				<option>23</option>
				<option>24</option>
				<option>25</option>
				<option>26</option>
				<option>27</option>
				<option>28</option>
				<option>29</option>
				<option>30</option>
				<option>31</option>
			</select>

How can I make it shorter? It´s too costly to write it all. And you can choose for example 30th February and that´s impossible.
Posted
Updated 24-Dec-11 21:46pm
v2
Comments
Sergey Alexandrovich Kryukov 24-Dec-11 19:50pm    
Why?
--SA
Chi Ller 24-Dec-11 19:57pm    
Maybe you know it´s no 30th february or 31th november.
so how can i do it easier?

This will fill the combo box with the given month in a given year, days.

HTML
<HTML>
	<HEAD>
		<SCRIPT language="javascript">
		    function add(dumpMonth, dumpYear) {
		        var combo = document.getElementById("combo");
		        days = 32 - new Date(dumpYear, dumpMonth - 1, 32).getDate();

                for(i=1; i<=days; i++)
		         {
		            option = document.createElement("option");
		            option.text = i;
		            option.value = i;
		            try {
		                combo.add(option, null); 
		            } catch (error) {
		                combo.add(option);
		            }
		        }
		    }
</SCRIPT>
</HEAD>
    <BODY onload="add(2,2011)">
        Select Day: <select name="combo" id="combo"></select>
    </BODY>
</HTML>


Hope it helps.
 
Share this answer
 
I fail to see why it is too costly, the CTRL V button is re-usable.
However, as others have pointed out, the date function is available and should be used.



Or you could load by a looped array.
Just use a case for the months and bobs your uncle.
 
Share this answer
 
Use JavaScript to create the select and option elements. Use the Date[^] object and create a loop.
 
Share this answer
 
Try
PHP
$("#amount").keyup(function(){
    var $combo = $('#combo');
    $combo.html('');
    var value = parseInt($('#amount').val(), 10);
    for (i = 1; i <= value; i++) {
        var $option = $('<option>').val(i).html(i);
        $combo.append($option);
    }
})


Get practical Demo of above code from there[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900