Good people, it turns out that I have a topic, I am making an interface to control an arduino that I have, and what I did was with JavaScript to send a GET request when the power button is pressed and another when the power button is pressed, what I want is to use un checkbox
and that when selecting it the function is executed on()
and when deselecting it the functionoff()
<script type="text/javascript">
function on2() {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "http://192.168.0.104/r2=ON";
xmlhttp.open("GET", url, false);
xmlhttp.send(null);
var respo= xmlhttp.responseText;
}
function off2() {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "http://192.168.0.104/r2=OFF";
xmlhttp.open("GET", url, false);
xmlhttp.send(null);
var respo= xmlhttp.responseText;
}
</script>
You can perform a condition by checking whether the checkbox is true or false with the
checked
checkbox attribute.You can then assign an event to the checkbox to run when its state has changed by using the function
addEventListener
and telling it to run with the eventchange
.Example:
You can do it like this: