0

Good afternoon,

I am trying to integrate several scripts in one html page. Unfortunately, I get an error on line 49 : setInterval(check,1000). It says that 'check' is undefined. However, I have a function defined a few lines above (line 28) named 'check'?

Can you please explain me what I have missed?

Many thanks in advance for your help and best wishes, Laurent

<!DOCTYPE html>
<html>
<head>
<title>!Domooslab prototype!</title>
<meta charset="utf-8" />
<link type="text/css" rel="stylesheet" href="css/rcswitcher1.min.css">
<link type="text/css" rel="stylesheet" href="css/tabs.css">
<link type="text/css" rel="stylesheet" href="css/mystyle_day.css">
<script type="text/javascript" src="scripts/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="scripts/rcswitcher.min.js"></script>
<script type="text/javascript" src="scripts/modernizr.js"></script>    
<meta name="viewport" content="width=device-width, initial-scale=1">        <!-- est-ce que cette ligne est nécessaire?-->
<script>
/* AJAX request to checker */
$(document).ready(
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){
var j = response.news;

$('#message-list').html(response.news);
disBonjour(j);
}
});
});
//Every 1/2 sec check if there is new update
setInterval(check,500);
</script>
<script>
function disBonjour(j){
//console.log("Coucou");

var json=$.parseJSON(j);
var techname = "";
$(json).each(function(i,val){
$.each(val,function(k,v){

if (k=="tech_name")
{
techname = v;
}
else
{
// console.log("Coucou");
console.log("Mon nom est " + techname + " et ma valeur est " + v);
if (v==0)
{
// false

uncheckBox(techname);
}
else
{
// true
checkBox(techname);
}
}

});
});

}
function checkBox(pCtrl)
{
document.getElementById(pCtrl).checked = true;
}
function uncheckBox(pCtrl)
{
document.getElementById(pCtrl).checked = false;
}
</script>
<script>
window.onload = function(){
$('.permissions :checkbox').rcSwitcher({
// reverse: true,
// inputs: true,                    
blobOffset: 0,
onText: 'ON',
offText: 'OFF',
theme: 'light',
// autoFontSize: true,
autoStick: true,
})
// Listen to status changes
.on( 'turnon.rcSwitcher', function( e, data ){

console.log( "New value " + data.$input[0].name + ": " + data.$input[0].checked);
//alert("New value " + data.$input[0].name + ": " + data.$input[0].checked);
})          
.on( 'turnoff.rcSwitcher', function( e, data ){

console.log( "New value " + data.$input[0].name + ": " + data.$input[0].checked);
//alert("New value " + data.$input[0].name + ": " + data.$input[0].checked);
})
;
};
</script>

<script>

$(document).ready(
function() {
setInterval(function() {
var randomnumber = Math.floor(Math.random() * 1000);
$('#show').text(
        'I am getting refreshed every second..! Random Number ==> '
                + randomnumber);
$('#Chambre').html('Coucou');
console.log("Random number : " + randomnumber);

}, 1000);

$('#boxid').click(function() {
if ($(this).is(':checked')) {
$(this).siblings('label').html('checked');
} else {
$(this).siblings('label').html(' not checked');
}
});
});
</script>

</head>
<body>

<h2>Prototype v0.1 (tabs + switch + random)</h2>
<p>Source: <a href="http://www.jqueryrain.com/" target="_blank">http://www.jqueryrain.com/</a></p>
<dl class="accordion">
<dt class="accordion__title">Switches</dt>
<dd class="accordion__content">
<section class="container clear-fix">
<div class="permissions block">
<h4>&larr;Lumieres</h4>         
<label >Chambre 1</label><input type="checkbox" name="ch1" value="ch1" id="chk1">
<label >Chambre 2</label><input type="checkbox" name="ch2" value="ch2" id="chk2">
<label >Chambre 3</label><input type="checkbox" name="ch3" value="ch3" id="chk3">
</div>
<div class="permissions block">
<h4>Sliders</h4>            
<label >Chambre 4</label><input type="checkbox" name="ch4" value="ch4">
<label >Chambre 5</label><input type="checkbox" name="ch5" value="ch5" checked >
</div>
<div class="permissions block">
<h4>Lumieres</h4>           
<label for="Chambre">Chambre 6</label><input type="checkbox" name="ch6" value="ch6">
<label >Chambre 7</label><input type="checkbox" name="ch7" value="ch7" checked >
</div>
</section>
<div id="show" align="center"></div>
<input id="boxid" type="checkbox"><label for="boxid">not checked</label>
</dd>
<dt class="accordion__title">Slider</dt>
<dd class="accordion__content">

</dd>
<dt class="accordion__title">Item 2<img src="image.gif" style="width:30px;height:30px;"></dt>
<dd class="accordion__content">
<p><b>Item 2 content.</b> Ut laoreet augue et neque pretium non sagittis nibh pulvinar. Etiam ornare tincidunt orci quis ultrices. Pellentesque ac sapien ac purus gravida ullamcorper. Duis rhoncus sodales lacus, vitae adipiscing tellus pharetra sed. Praesent bibendum lacus quis metus condimentum ac accumsan orci vulputate. Aenean fringilla massa vitae metus facilisis congue. Morbi placerat eros ac sapien semper pulvinar. Vestibulum facilisis, ligula a molestie venenatis, metus justo ullamcorper ipsum, congue aliquet dolor tortor eu neque. Sed imperdiet, nibh ut vestibulum tempor, nibh dui volutpat lacus, vel gravida magna justo sit amet quam. Quisque tincidunt ligula at nisl imperdiet sagittis. Morbi rutrum tempor arcu, non ultrices sem semper a. Aliquam quis sem mi.</p>.
<p><img src="image.gif"></p>
</dd>
<dt class="accordion__title">Item 3</dt>
<dd class="accordion__content">
<p><b>Item 3 content.</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tincidunt pellentesque lorem, id suscipit dolor rutrum id. Morbi facilisis porta volutpat. Fusce adipiscing, mauris quis congue tincidunt, sapien purus suscipit odio, quis dictum odio tortor in sem. Ut sit amet libero nec orci mattis fringilla.</p>
<p>Praesent eu ipsum in sapien tincidunt molestie sed ut magna. Nam accumsan dui at orci rhoncus pharetra tincidunt elit ullamcorper. Sed ac mauris ipsum. Nullam imperdiet sapien id purus pretium id aliquam mi ullamcorper.</p>
</dd>  
<dt class="accordion__title">Links</dt>
<dd class="accordion__content">    
<p>Progress pie : <a href="http://www.jqueryrain.com/?eBub464Q" target="_blank"> http://www.jqueryrain.com/?eBub464Q</a></p>
<p>Roundslider : <a href="http://www.jqueryrain.com/?ot4e1H_o" target="_blank"> http://www.jqueryrain.com/?ot4e1H_o</a></p>
<p>Another one : http://www.developerdrive.com/2012/07/creating-a-slider-control-with-the-html5-range-input/</p>
<p>RcSwitcher : <a href="http://www.jqueryrain.com/?1oB4im4M" target="_blank"> http://www.jqueryrain.com/?1oB4im4M</a></p>
<p>Toggle buttons : <a href="https://www.sanwebe.com/2014/02/css3-buttons-examples-with-effects-animations " target="_blank"> https://www.sanwebe.com/2014/02/css3-buttons-examples-with-effects-animations </a></p>
</dd>
</dl>
<script src="scripts/accordion.js"></script>    
</body>    
</html>
Laurent
  • 711
  • 2
  • 12
  • 30
  • You function `check` needs to be globally accessible, so put it outside the `$(document).ready`. – Sebastian Simon Jul 03 '16 at 13:32
  • Thanks a lot. I have removed the $document.ready part and I no longer gets the error. Now, a second problem is happening. I have integrated the rcSwitcher script (http://www.jqueryrain.com/?1oB4im4M) and it turns out that the switches do not turn on even if, according to the result [if (v==0) ...], they should. Any idea? – Laurent Jul 03 '16 at 13:44
  • You removed `$document.ready`? But you should’ve only placed the `check` function outside of it. Not sure how to solve your second problem. – Sebastian Simon Jul 03 '16 at 13:48
  • Thanks anyway Xufox. It is already a great step forward. – Laurent Jul 03 '16 at 13:52

0 Answers0