JavaScript function to create HTML select option elements
Just a warning: in its current implementation your code works only if countOptionsStart is less than or equal to countOptionsEnd!
So depending on your actual needs you should check this case to exit without generating options, or adapt code to work also in this case.

In the other hand, I suggest you some improvements about process of filling value with zeroes. It dramatically reduces code size, and probably works faster:



// Trying it out.
var selects = document.querySelectorAll('.drop-down');
selects = Array.prototype.slice.call(selects);

createOptions(selects[0], -9, 9, 8);

for (var i = 1; i &lt; selects.length; i++) {
  createOptions( selects[i], 
                 i * (-1 * Math.pow(10, i)),
                 i * Math.pow(10, i));
}

function createOptions( selectElement,
                        countOptionsStart,
                        countOptionsEnd,
                        preSelected ) {
  preSelected = preSelected || 0;
  demand = Math.max(
    countOptionsStart.toString().length,
    countOptionsEnd.toString().length);
  for (var i = countOptionsStart; i &lt;= countOptionsEnd; i++) {
    var option = document.createElement('option'),
        strI = Math.abs(i) + '',
        sign = i &lt; 0 ? '-' : '',
        fill = i &lt; 0 ? demand -1 : demand;
    option.setAttribute('value', i);
    if (i === preSelected) option.setAttribute('selected', 'selected');
    option.innerHTML = sign + '0'.repeat(fill - strI.length) + strI;
    selectElement.appendChild(option);   
  }
}
&lt;select class="drop-down"&gt;&lt;/select&gt;
&lt;select class="drop-down"&gt;&lt;/select&gt;
&lt;select class="drop-down"&gt;&lt;/select&gt;
&lt;select class="drop-down"&gt;&lt;/select&gt;