-
Notifications
You must be signed in to change notification settings - Fork 3
/
tst.html
56 lines (49 loc) · 1.64 KB
/
tst.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tag Values Example</title>
</head>
<body>
<!-- Radio field to select tag set -->
<input type="radio" name="tagSet" value="tag1" checked> Tag Set 1
<input type="radio" name="tagSet" value="tag2"> Tag Set 2
<!-- Tags for Tag Set 1 -->
<div class="tag1 tag-set">
<div class="tag" data-value="1">Tag A</div>
<div class="tag" data-value="2">Tag B</div>
<div class="tag" data-value="3">Tag C</div>
</div>
<!-- Tags for Tag Set 2 -->
<div class="tag2 tag-set" style="display:none;">
<div class="tag" data-value="4">Tag D</div>
<div class="tag" data-value="5">Tag E</div>
<div class="tag" data-value="6">Tag F</div>
</div>
<!-- Script to handle radio field change -->
<script>
document.querySelectorAll('input[name="tagSet"]').forEach(radio => {
radio.addEventListener('change', function() {
document.querySelectorAll('.tag-set').forEach(tagSet => {
tagSet.style.display = 'none';
});
document.querySelector('.' + this.value).style.display = 'block';
});
});
// Storing the numerical values of tags in different arrays based on radio selection
let tagValuesArrays = {
tag1: [],
tag2: []
};
document.querySelectorAll('.tag').forEach(tag => {
tag.addEventListener('click', function() {
let tagValue = parseInt(this.getAttribute('data-value'));
let tagSet = document.querySelector('input[name="tagSet"]:checked').value;
tagValuesArrays[tagSet].push(tagValue);
console.log(tagValuesArrays);
});
});
</script>
</body>
</html>