JSFiddle - React, Tailwind, and code Playground
by Tintu Raju
HTML
<script>
function inArray(needle, haystack) {
var length = haystack.length;
for(var i = 0; i < length; i++) {
if(haystack[i] == needle) return true;
}
return false;
}
function displayrand()
{
var counter = document.getElementById("no1").value;
counter = parseInt(counter);
var numbers = [];
var new_html = "";
for(var i=0;i<counter;){
var random_num = Math.floor((Math.random() * 10) );
if(!inArray(random_num,numbers)) {
numbers.push(random_num);
new_html +="<input type='text' value='"+random_num+"'>";
i++;
}
}
document.getElementById("no2").value=numbers;
document.getElementById("dv").innerHTML = new_html;
}
</script>
</head>
<body>
<div class="form-inline">
<div class="col-xs-12">
<form action="" onclick="check()">
<div class="form-group">
<input type="text" class="form-control" id="no1" name="no1" placeholder="No 1" maxlength="1">
</div>
<div class="form-group">
<label for="exampleInputName2"></label>
<input type="text" class="form-control" id="no2" name="no2" placeholder="No 2" maxlength="1">
</div>
</form>
<button type="button" class="btn btn-primary" onclick="displayrand()">Populate</button>
</div>
</div>
</div>
<div id='dv'></div>