My question is, how to create a button that randomly and automatically selects 3 of the 5 numbers that are shown. Like I clicked on them.
Follow all my code below.
<html>
<head>
<style type="text/css">
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label {
color: black;
border: 1px solid #000;
padding-left: 10px;
padding-right: 10px;
padding-top: 5px;
padding-bottom: 5px;
}
input#input_1_1:checked + label {
color: white;
background-color:#4682B4;
font-weight: 500;
border: 1px solid #000;
}
input#input_1_2:checked + label {
color: white;
background-color:#4682B4;
font-weight: 500;
border: 1px solid #000;
}
input#input_1_3:checked + label {
color: white;
background-color:#4682B4;
font-weight: 500;
border: 1px solid #000;
}
input#input_1_4:checked + label {
color: white;
background-color:#4682B4;
font-weight: 500;
border: 1px solid #000;
}
input#input_1_5:checked + label {
color: white;
background-color:#4682B4;
font-weight: 500;
border: 1px solid #000;
}
</style>
</head>
<body>
<input type="text" id="resultado">
<input type='checkbox' name='q1_myOptions[]' onclick="add(this)" value="01" id="input_1_1"/>
<label for="input_1_1">01</label>
<input type='checkbox' name='q1_myOptions[]' onclick="add(this)" value="02" id="input_1_2"/>
<label for="input_1_2">02</label>
<input type='checkbox' name='q1_myOptions[]' onclick="add(this)" value="03" id="input_1_3"/>
<label for="input_1_3">03</label>
<input type='checkbox' name='q1_myOptions[]' onclick="add(this)" value="04" id="input_1_4"/>
<label for="input_1_4">04</label>
<input type='checkbox' name='q1_myOptions[]' onclick="add(this)" value="05" id="input_1_5"/>
<label for="input_1_5">05</label>
<script>
function add(_this){
var resultado = document.getElementById('resultado');
var value = _this.value;
var hasAdd = resultado.value.search(_this.value) > 0
if(_this.checked && !hasAdd){
resultado.value += ' '+_this.value;
}else if(!_this.checked && hasAdd){
var er = new RegExp(_this.value, 'ig');
resultado.value = resultado.value.replace(er, '');
}
resultado.value = resultado.value.replace(/ {2,}/g, ' ');
}
</script>
</body>
</html>