aidaghazaryan aidaghazaryan - 1 month ago 7
HTML Question

display only hundreds and thousands in the dropdown

I need to create a dropdown which will give opportunity to choose only hundreds and thousands

(100, 200, 300, 400, ..., 1000, 2000, 3000...10000, etc...)
.

I tried this:

for (i=100;i<=10000;i++){
$selectBox.append($('<option></option>').val(i).html(i))
}


But with above code
i
variable also counts 101,102,103,... but I need only hundreds and thousands.

Any ideas please?

Answer

If I understand you correctly, The trick is so add 100 to i in each iteration.

var $selectBox = $('select');
for (i=100;i<=10000;i+=100){
   $selectBox.append($('<option></option>').val(i).html(i))
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select>
  
</select>

Comments