My problem is that I want to select maybe 20 out of 100 checkboxes and then get 10 random out of the 20 selected.
I have already tried with Math.floor(Math.random() but without any luck, I cant figure out how to combine the two if it's possible at all
(This is my first question, hope you can help. Thanks)
function getValue() {
var checks = document.getElementsByClassName('checks');
var str = 'Selected = ' + '<br>';
for (i = 0;
[i] < checks.length; i++) {
if (checks[i].checked === true) {
str += checks[i].value + ", " + "<br>";
}
}
document.getElementById("Selected").innerHTML = str + "end";
}
<button onclick="getValue()">Click me</button>
<div class="prøve">
<div class="option">
<input type="checkbox" class="checks" value="film & animation" />
<label>Film & Animation</label>
</div>
<div class="option">
<input type="checkbox" class="checks" value="science" />
<label>Science & Technology</label>
</div>
<div class="option">
<input type="checkbox" class="checks" value="art" />
<label>Art</label>
</div>
<div class="option">
<input type="checkbox" class="checks" value="music" />
<label>Music</label>
</div>
<div class="option">
<input type="checkbox" class="checks" value="travel" />
<label>Travel & Events</label>
</div>
<div class="option">
<input type="checkbox" class="checks" value="sports" />
<label>Sports</label>
</div>
<div class="option">
<input type="checkbox" class="checks" value="news" />
<label>News & Politics</label>
</div>
<div class="option">
<input type="checkbox" class="checks" value="tutorials" />
<label>Tutorials</label>
</div>
</div>
<div id="Selected">All Selected</div>