Good afternoon,
I am trying to tick a checkbox in my html page using a script.
Unfortunately, I get the following error message :
SCRIPT5007: Unable to set property 'checked' of undefined or null reference File: ajax3, Line: 37, Column: 5
Do you have an idea what went wrong in my code?
Thanks a lot and have a great Sunday.
Laurent
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Demo for Ajax Auto Refresh</title>
<link rel="stylesheet" type="text/css" href="css/mystyle_day.css" />
<script src="jquery-2.1.3.min.js"></script>
<script>
/* AJAX request to checker */
function check(){
$.ajax({
type: 'POST',
url: 'checker.php',
dataType: 'json',
data: {
counter:$('#message-list').data('counter')
}
}).done(function( response ) {
/* update counter */
$('#message-list').data('counter',response.current);
/* check if with response we got a new update */
if(response.update==true){
$('#message-list').html(response.news);
sayHello();
}
});
}
//Every 1 sec check if there is new update
setInterval(check,1000);
</script>
<script>
function sayHello(){
//console.log("Coucou");
check();
}
function check() {
document.getElementById("chk1").checked = true;
}
function uncheck() {
document.getElementById("chk1").checked = false;
}
</script>
</head>
<body>
<div id="message-list" data-counter="<?php echo (int)$db->check_changes();?>">
</div>
<input type="checkbox" name="chk1" id="chk1"> Living room<br>
<input type="checkbox" name="chk2" id="chk2"> Entrance<br>
<input type="checkbox" name="chk3" id="chk3"> Kitchen<br>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire