Javascript Form How to - Build Option Tag With Custom Increments for Select element








Question

We would like to know how to build Option Tag With Custom Increments for Select element.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!--  ww  w. j a va2s  . com-->
    var teamArray = ["(Custom Number Example) 120"];
    for (var i = 0; i <= 1000; i += 15) {
        teamArray.push(i);
    }
    var arLen=teamArray.length;
    for(var i=0; i<arLen; i++){
        document.getElementById("minutes").options[i]=new Option(teamArray[i], i);
    }
}
</script>
</head>
<body>
  <select id="minutes">
</body>
</html>

The code above is rendered as follows: