I have multi span ids like output1 , output2 , output3 but the following code is not working.
digitalRead(id,‘output’+index);
where index can have value 1,2 or 3.
I have multi span ids like output1 , output2 , output3 but the following code is not working.
digitalRead(id,‘output’+index);
where index can have value 1,2 or 3.
Hi @ankit.negi1525 ,
Please send us your full code snippet. Also, see if there is any error or warning message in console.
I think you are executing digitalRead inside for loop. Put some delay on each iteration.
you can refer this code snippet.
// (1) define the variable for the array index
var index = 0;
// (2) define the delayed loop function
function delayedLoop() {
span_id = "ouput" + index;
//digitalRead(0,span_id);
alert(span_id)
// (4) if the end of the array has been reached, stop
if (++index == 5) {
return;
}
// (5) recursively call the delayed loop function with a delay
window.setTimeout(delayedLoop, 3000);
}
delayedLoop(); // (6) start the loop
Hi ‘output’+index where index is a int cannot be used , the entire variable must be a string example
'digitalRead(id,("output"+String(index)))';
<!doctype html>
<html>
<head>
<title>BOLT</title>
<script type=“text/javascript” src="/serveFile?filename=bolt.js"> setDebug(true); </script>
</head>
<body bgcolor="#01FFFF" >
<center>
<h3> Sensor data </h3>
<span id=“output” style=“display:none;position:absolute;bottom:-30px”> Pin Val=1 </span>
<script>
digitalRead(4,“output”);
var c=document.getElementById(‘output’).innerHTML;
document.write©;
</script>
</body>
</html>
still not working @datta.naik
<html>
<head>
<title>BOLT</title>
<script type="text/javascript" src="/serveFile?filename=bolt.js"> setDebug(true); </script>
</head>
<body bgcolor="#01FFFF" >
<center>
<h3> Sensor data </h3>
<span id="output"> Pin Val=1 </span>
<script>
digitalRead(4,"output");
</script>
</body>
</html>
@ankit.negi1525 please try the above code , I have tested it, your style statement in span id was creating an issue
Also if you still face issues try this solution, and if you still face issues please send a screenshot of the console screen, when you open the page in google chrome → right click → inspect element → click console tab.
yeah its working now. thank you