...

View Full Version : a select with a long option list



yaelbe
11-11-2002, 02:48 PM
Hy all

there is a way to write this code in a shorter way, do i have to insert all the minutes as options in the select?

<form name="form1" method="post" action="">
Minutes:

<select name="select" size="1" multiple>
<option>00</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</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>
<option>32</option>
<option>33</option>
<option>34</option>
<option>35</option>
<option>36</option>
<option>37</option>
<option>38</option>
<option>39</option>
<option>40</option>
<option>41</option>
<option>42</option>
<option>43</option>
<option>44</option>
<option>45</option>
<option>46</option>
<option>47</option>
<option>48</option>
<option>49</option>
<option>50</option>
<option>51</option>
<option>52</option>
<option>53</option>
<option>54</option>
<option>55</option>
<option>56</option>
<option>57</option>
<option>58</option>
<option>59</option>
</select>
</form>
Thanks
Yael

MCookie
11-11-2002, 03:44 PM
Hi Yael,
Never seen a way to shorten that code. Well you can leave out the </option> tags, but that won't validate.

yaelbe
11-11-2002, 03:51 PM
thanks

Bosko
11-11-2002, 05:37 PM
<select multiple="multiple" id="select"></select>
<script>
for(var i=0;i<60;i++){
if(i<10){
document.getElementById("select").options[i] = new Option("0"+i,"0"+i);
}
else{
document.getElementById("select").options[i] = new Option(i,i);
}
}
</script>

MCookie
11-11-2002, 08:06 PM
Bosko, that's really beautiful.
Now, we're in the wrong forum to ask this, but how should one code something like this:

<option value="wait_a_minute.html">35</option>

Bosko
11-11-2002, 08:56 PM
You want to set the value for the options to "wait_a_minute.html",right?:

new Option("0"+i,"wait_a_minute.html");

new Option(i,"wait_a_minute.html");

Bosko
11-11-2002, 09:04 PM
I also made a DOM version of the script,which is faster if you have more options:


<select multiple="multiple" id="select"></select>
<script>
for(var i=0;i<60;i++){
var nieuw =document.createElement("option");
if(i<10){
nieuw.setAttribute("value","0"+i);
var Data = document.createTextNode("0"+i);
}
else{
nieuw.setAttribute("value",i);
var Data = document.createTextNode(i);
}
nieuw.appendChild(Data);
document.getElementById('select').appendChild(nieuw);
}
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum