-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkbox.html
60 lines (43 loc) · 1.81 KB
/
checkbox.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
57
58
59
60
<!DOCTYPE html>
<html>
<head>
<title>Checklist</title>
</head>
<body>
<form>
<p><input type="checkbox" id="item1" name="item1"> Item 1</p>
<p><input type="checkbox" id="item2" name="item2"> Item 2 </p>
<p><input type="checkbox" id="item3" name="item3"> Item 3 </p>
<button id="downloadHTML" type="button">Download HTML</button>
</form>
<script>
document.getElementById("downloadHTML").addEventListener("click", function() {
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
var items = Array.from(checkboxes).map(function(checkbox) {
return checkbox.id;
});
var htmlContent = ""
items.forEach(function(item) {
htmlContent += `<p><input type="checkbox" id="${item}" name="${item}" ${document.getElementById(item).checked ? "checked" : ""}> Item </p>\n`;
});
var blob = new Blob([saveSectionsToVariables(htmlContent)], {type: "text/html"});
var url = URL.createObjectURL(blob);
// Create a link and trigger a click to download
var a = document.createElement("a");
a.href = url;
a.download = "checklist.html";
a.click();
});
function saveSectionsToVariables(form) {
var scriptContent = document.querySelector('script').innerHTML;
var formContent = document.querySelector('form').innerHTML;
var bodyContent = document.body.innerHTML;
var headContent = document.head.innerHTML;
var documentContent = document.documentElement.outerHTML;
console.log("html Content:");
console.log(htmlContent);
return `<!DOCTYPE html>\n<html>\n<head>\n<title>Checklist</title>\n <form>\n ${form} \n</form> \n<script>\n ${scriptContent} \n</script> \n\n</body>\n</html>`;
}
</script>
</body>
</html>