Reputation: 339
I'm still new to Javascript and I need to know how to build the option tag. I want to keep the first option tag custom and the rest with increments of 15 from 0 - 1000. This is the current code I'm using but the problem is that the value is being set to the increment number and I don't want to keep typing each array value.
<script type="text/javascript">
function myFunction() {
var teamArray = ["(Custom Number Example) 120", "0", "15", "30", "45"];
var arLen=teamArray.length;
for(var i=0; i<arLen; i++){
document.getElementById("minutes").options[i]=new Option(teamArray[i], i);
}
}
window.onload=myFunction;
</script>
<select id="minutes">
</select>
Upvotes: 0
Views: 186
Reputation: 191789
JavaScript does not have a range
function built in, unfortunately, but you can create this array with a simple for
loop.
var teamArray = ["(Custom Number Example) 120"];
for (var i = 0; i <= 1000; i += 15) {
teamArray.push(i);
}
http://jsfiddle.net/ExplosionPIlls/Ne8XD/
Upvotes: 3