0
I have a "checkbox" button with a JS event, the JS events are running normally, but I would like my JS code to run a file. py when checkbox is checked. How can I do this?
this is the html code
<div class="switch__container" >
<input id="switch-shadow" class="switch switch--shadow" type="checkbox"name="field[]" value="1">
<label for="switch-shadow"></label>
<script src="js/teste.js"></script>
</div>
this is the JS code:
var checkbox = $("#switch-shadow[type='checkbox']");
checkbox.change(function(event) {
var checkbox = event.target;
if (checkbox.checked) {
setTimeout(function(){
alert("Luz do quarto Acessa")
}, 1000);
}
else {
setTimeout(function(){
alert("Luz do quarto Desligado")
}, 1000);
}
});
What’s more, my back-end is in python. That’s the code:
import RPi.GPIO as GPIO
import time
import cgi, cgitb
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(5)
print "LED off"
GPIO.output(18,GPIO.LOW)
Do you have a backend? In what language?
– Felipe Avelar
python, this is the python code: GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18,GPIO. OUT) print "LED on" GPIO.output(18,GPIO. HIGH) time.Sleep(5) print "LED off" GPIO.output(18,GPIO. LOW)
– Arnaldo Filho
It would not be the case to make an ajax when it selected the checkbox?
– Felipe Avelar
yes, exactly but I’m not getting to structure it on my JS
– Arnaldo Filho