There is a weird situation with the while loop in my jQuery code. I have a textbox and I want to split the input by ... and create an array. Then I want to put the array back into the textbox.
For example I put 1...3 and what I want is 1,2,3 in the textbox. The weird part is that the script doesn't work for some values. If I put 1...10 it works however if I try 5...10 nothing happens.
Here is my code, what am I missing? Thanks.
$(function() {
$("#test").change(function() {
var val = $("#test").val();
var val2 = val.split("...");
var arr = [];
var valindex1 = val2[0];
var valindex2 = val2[1];
while (valindex1 <= valindex2) {
arr.push(valindex1);
valindex1++;
}
if (arr.length != 0) {
$("#test").val(arr);
}
})
})
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<input id="test" type="text">