Jump to content

Typos on "Node.js and Raspberry Pi - Webserver with WebSocket" Page


Recommended Posts

Hello, looks like there's a minor error in the example code given for the index.html page for the "Node.js and Raspberry Pi - Webserver with WebSocket" page (which I'm very grateful was provided, btw). Half way through the article, there's an index.html example that has an extra html opening tag, and extra close body and html tags.  It's not an issue for people who realize the issue, but figured the page could use a quick update if possible.  Thank you for all the great content!

Ref: https://www.w3schools.com/nodejs/nodejs_raspberrypi_webserver_websocket.asp

<!DOCTYPE html>
<h1>Control LED light</h1>
<p><input type="checkbox" id="light"></p>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script> <!-- include socket.io client side script -->
var socket = io(); //load socket.io-client and connect to the host that serves the page
window.addEventListener("load", function(){ //when page loads
  var lightbox = document.getElementById("light");
  lightbox.addEventListener("change", function() { //add event listener for when checkbox changes
    socket.emit("light", Number(this.checked)); //send button status to server (as 1 or 0)
socket.on('light', function (data) { //get button status from client
  document.getElementById("light").checked = data; //change checkbox according to push button on Raspberry Pi
  socket.emit("light", data); //send push button status to back to server


Link to comment
Share on other sites

It is probably faster to reach them by email. I am not sure how frequently they look at the forums. At the bottom of each page is a button labeled "Report error". If you click on it it displays the email address (help@w3schools.com) to which you can indicate a mistake on any page.

Link to comment
Share on other sites

  • 2 weeks later...

Hello...thanks for this information. I m trying to power a led and shut it down by 2 buttons ,i want that led state is shown on a web page where i can also control it from here. I know i may just use 1 button to do both by code but i need 2 buttons as final goal.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...