I searched over the internet, but nothing seems like my problem. I want to add question numbersfor questions in the box text, and the numbers should be unique. I am trying to check if there is array of numbersan array with the number of questions (e.g. 8 questions), then if it is in the array, you can enter the number as long as it is not entered yet, but my code is not at work. How can i do this? See my code below for reference.
$(document).ready(function(){
var try1;
var arrayLen = $('#question\\[\\]').length;
var numArray = [];
var convertedArray;
for(i = 1; i <= arrayLen; i++){
numArray.push(i);
}
$('#question\\[\\]').on('input', function(){
if($.inArray($(this).val(), numArray) !== -1){
$('#result').html("available");
} else{
$("#result").html("not available");
return false;
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="question[]" placeholder="multipleChoice"><br><br>
<input type="text" id="question[]" placeholder="trueFalse"><br><br>
<input type="text" id="question[]" placeholder="shortAnswer"><br><br>
<input type="text" id="question[]" placeholder="shortAnswer"><br><br>
<input type="text" id="question[]" placeholder="description"><br><br>
<input type="text" id="question[]" placeholder="multipleChoice"><br><br>
<input type="text" id="question[]" placeholder="multipleChoice"><br><br>
<input type="text" id="question[]" placeholder="trueFalse"><br><br>
<span id="result"></span>
Run codeHide resultAccepted answer: but UPDATE required
Accepted answer from @Shiladitya
source
share