Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Nov 2002
    Location
    Israel
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    a select with a long option list

    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

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    NL
    Posts
    421
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Yael,
    Never seen a way to shorten that code. Well you can leave out the </option> tags, but that won't validate.

  • #3
    New Coder
    Join Date
    Nov 2002
    Location
    Israel
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <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>

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    NL
    Posts
    421
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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");

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I also made a DOM version of the script,which is faster if you have more options:
    Code:
    <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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •