-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.php
158 lines (126 loc) · 3.2 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!-- For testing -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
$max = 10;
$min = 1;
$select_q = 3;
?>
<table>
<tr>
<td>1</td>
<td>helo</td>
<td><input type="checkbox" id="1"></td>
</tr>
<tr>
<td>2</td>
<td>helo</td>
<td><input type="checkbox" id="2"></td>
</tr>
<tr>
<td>3</td>
<td>helo</td>
<td><input type="checkbox" id="3"></td>
</tr>
<tr>
<td>4</td>
<td>helo</td>
<td><input type="checkbox" id="4"></td>
</tr>
<tr>
<td>5</td>
<td>helo</td>
<td><input type="checkbox" id="5"></td>
</tr>
<tr>
<td>6</td>
<td>helo</td>
<td><input type="checkbox" id="6"></td>
</tr>
<tr>
<td>7</td>
<td>helo</td>
<td><input type="checkbox" id="7"></td>
</tr>
<tr>
<td>8</td>
<td>helo</td>
<td><input type="checkbox" id="8"></td>
</tr>
<tr>
<td>9</td>
<td>helo</td>
<td><input type="checkbox" id="9"></td>
</tr>
<tr>
<td>10</td>
<td>helo</td>
<td><input type="checkbox" id="10"></td>
</tr>
</table>
<button id="select_random">Random</button>
<div id="output">here</div>
<!-- For selection Random Quesrions -->
<script type="text/javascript">
let random_active = 0;
let btn = document.getElementById('select_random');
let output = document.getElementById('output');
let smax = <?php echo $max ?>;
let smin = <?php echo $min ?>;
let sselect = <?php echo $select_q ?>;
let random_array = [];
let random_array_q = [];
let temp = 0;
function getRandomNumber(min, max) {
let step1 = max - min + 1;
let step2 = Math.random() * step1;
let result = Math.floor(step2) + min;
return result;
}
function createArrayOfNumbers(start, end){
let myArray = [];
for(let i = start; i <= end; i++) {
myArray.push(i);
}
return myArray;
}
let numbersArray = createArrayOfNumbers(smin,smax);
btn.addEventListener('click', () => {
if (random_active == 1) {
}
let it = 0;
while (it<=smax) {
it++;
if(numbersArray.length == 0){
while (temp<sselect) {
var a = random_array[temp];
random_array_q.push(a);
temp = temp + 1;
}
random_array_q.forEach(element => {
const ran = document.getElementById(element);
ran.checked = true;
});
random_active = 1;
output.innerText = random_array_q;
return;
}
let randomIndex = getRandomNumber(0, numbersArray.length-1);
let randomNumber = numbersArray[randomIndex];
numbersArray.splice(randomIndex, 1);
output.innerText = randomNumber;
random_array.push(randomNumber);
console.log(random_array);
}
});
</script>
<!-- <input type="checkbox" class="btn-check" name="quiz_question[]" id="btn-check-4-outlined" autocomplete="off" value="46" onclick="return select_only()"> -->
</body>
</html>