0
I need to maintain the variable’s previous state checked of input
guy checkbox
, after the page is loaded. In the current state, every time it is loaded, the checkbox
returns to unchecked condition.
I would like a solution, through Javascript.
<html>
<head>
<title>CSS SWITCH</title>
<meta charset="UTF-8">
<script type="text/javascript">
function ChecksVerify() {
var aChk = document.getElementsByName("item");
for (var i=0;i<aChk.length;i++){
if (aChk[i].checked == true){
aChk[i].value = "?f=on";
} else {
aChk[i].value = "?f=off";
}
window.location.assign(aChk[i].value);
alert(aChk[i].value + " enviado");
}
}
</script>
</head>
<body>
<div class="switch__container">
<p align='center'>
<input type="checkbox" name="item" onclick="ChecksVerify()">
<label for="switch-shadow"></label>
</p>
</div>
</body>
</html>
The HTTP protocol is stateless (stateless), that is, it does not store the state and each request is made independently of the previous ones, however you can persist the value of checkbox in the user’s browser with localStorage. Knows?
– Woss