Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Parallax WX Wi-Fi Module for Prop C

Parallax WX Wi-Fi Module for Prop C

Relay Information with JavaScript

One common task for Internet of Things (IoT) applications is for a page to send information to a “thing” on the internet.  Whether it’s a web-controlled robot, a remote-controlled alarm system, or whatever else you can imagine, the principle is pretty much the same: the JavaScript code has to be able to accept an input, and send information to the Internet thing about the input it received.

Before sending info to your Activity Board’s Propeller microcontroller through the Wi-Fi module, let’s start with using JavaScript to change text in a web page.

  • Use your text editor to enter and save this as 05-button-changes-text.html.
  • Open it with your Chrome browser and verify that the text below the button changes after you click it.
<html>
  <button onclick = "changeText()">Change Text</button>
  <p id = "myText">Click button to change this text.</p>
 
  <script>
    function changeText()
    {
       document.getElementById("myText").innerHTML =
       "Hey, look, the text changed!!!";
    }
  </script>
</html>

 

How it Works

In this example, the paragraph <p> tag was expanded to <p id = “myText”>.  With this identifier, the JavaScript can modify this paragraph element using document.getElementById(“myText”).innerHTML = “Hey, look, the text changed!!!”;  
In JavaScript, document is an example of an object.  Objects have methods, which are actions that can be performed on their data, like getElementById(“myText”), which finds the element with  the myText ID.  Objects also have properties, and innerHTML is an example of one of the document object’s properties.  By setting that innerHTML equal to “Hey, look, the text has changed!!!”, it replaces the existing innerHTML – Click button to change this text.”

 

Try This

We’ve given HTML button and paragraph elements IDs so that JavaScript can access and modify them.  In this example, JavaScript uses a text input’s ID to get information, adds some text to it, and then displays that text in the web page.

  • Click your text editor’s file menu, and select Save As…
  • This time, name your file 06-text-enter-display.html.
  • Open it with your Chrome browser.
  • Type some text into the text input.
  • Click the Enter button and verify that it displays “You typed: “ followed by the message you typed.
<html>
  <p>Type something, then click Enter: </p>
  <input type = "text" id = "textField">
  <button onclick = "changeText()">Enter</button>
  <p id = "myText">Waiting...</p>
 
  <script>
    function changeText()
    {
       var x = document.getElementById("textField").value;

       document.getElementById("myText").innerHTML =
       "You typed: " + x;
    }
  </script>
</html>

 

How it Works

This creates the text input and gives it an ID <input type = “text” id = “textField”>.  The button and paragraph also have IDs: <button onclick = “changeText()”>Enter</button> and <p id = “myText”>Waiting…</p>. 

Inside the changeText function, var x = document.getElementById(“textField”).value declares a variable named x that receives the value contained in the text input.  Next, document.getElementById(“myText”).innerHTML = “You typed: ” + x; adds “You typed: “ to whatever you typed in the text input and puts it in the paragraph with the myText ID. 

This application of client server communication through JavaScript is called AJAX, and there’s some great tutorials on it too:   

  • w3schools.com AJAX Tutorial
  • Tutorialspoint.com AJAX Tutorial

Printer-friendly version
Get Started With JavaScript
Prev
Send Web Page Event Info to the Propeller
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress