Retrieve information from the Arduino board

Hello everyone, I have a script that retrieves data from my Arduino board.

<script>                        
    var level = 0;
    var dataValue = 0;                                 

    function fetchArduinoData()
    {
        nocache = "&nocache=" + Math.random() * 1000000;
        var request = new XMLHttpRequest();
        request.onreadystatechange = function()
        {
            if (this.readyState == 4) {
                if (this.status == 200) {
                    if (this.responseXML != null) {
                        document.getElementById("input3").innerHTML = this.responseXML.getElementsByTagName('analog')[0].childNodes[0].nodeValue;
                        dataValue = this.responseXML.getElementsByTagName('analog')[0].childNodes[0].nodeValue;
                    }
                }
            }
        }
        request.open("GET", "ajax_inputs" + nocache, true);
        request.send(null);
        setTimeout('fetchArduinoData()', 200);
    }

</script>

However, I am facing an issue where I cannot access the value stored in dataValue on another script:

<script>
    var currentLevel = dataValue;
</script>

Can someone please assist me with this problem?

Answer №1

To fetch the same value received from the server stored in the local HTML, you can utilize the existing method to extract the value in the "other script".

//snippet from the "other script"
var level = document.getElementById("input3").innerHTML;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Learn how to default export React with withRouter, all while taking advantage of Material UI's makeStyles

I have been working on integrating Material UI makeStyles with class components, passing useStyles as props while default exporting it in an arrow function. export default () => { const classes = useStyles(); return ( <LoginClass classes={cl ...

What is the reason behind the increasing popularity of single quotes in JavaScript files in recent times?

What is the reason behind the increasing trend of using single quotes ' instead of double quotes " around string in JavaScript? Are there minification or linting tools that adhere to the convention of using double quotes for strings and single quotes ...

JavaScript's innerHTML property is failing to update

Hello there, I am currently attempting to update the innerHTML content of the script below: <div id="global-alert-queue" class="layout-wrapper"> <div class="alert success animate-in" role="alert"> Your submission was successful. <button i ...

Reviewing user input for any inappropriate characters using jQuery's functionality

When a username is inputted into the input box, I want to make sure that only valid characters are accepted. The following code shows what I have so far; but what should I replace "SOMETHING" with in the regular expression? var numbers = new RegExp( ...

Setting the cache to false during an httpget request in an mvc4 controller action: tips and tricks

My httpget request to a controller action looks like this: $.get('/Course/ExplanationCorrect/', postData, function (data) { $('#SurveyDiv').html(data); }); While it works on all other browsers, I'm facing an issue with IE10 o ...

Updating input value using React state

Hey there, I'm currently using a color picker to update my this.state.colorPicked value, which is working well. Now, I want to create a function that will concatenate the state's colorPicked value with the input field when called. If the input fi ...

Create a feature that allows users to search as they navigate the map using Leaflet

Exploring the idea of incorporating a dynamic "Search as I move the map" feature similar to Airbnb using Leaflet. Striving to strike a balance between loading data relevant to the displayed portion of the map and minimizing unnecessary API requests trigger ...

Obtain information from the <div> tag using Ajax/jQuery for inline text modification

I've spent several hours working on this issue, but I seem to have made a mistake somewhere in the javascript file. Unfortunately, I'm struggling to pinpoint where exactly the error lies. At the moment, when the alert(msg) function is triggered, ...

Moving a DIV below a fixed-positioned element

I have a website with a scrollable div. It works well, but I also need an absolutely positioned div on top of it - and it still needs to scroll smoothly without any hindrance. You can check out a basic JSFiddle demonstration here: http://jsfiddle.net/41ra ...

The measurement of a table cell's height containing hidden overflow child elements

I am looking to determine the actual height of the content within a table cell that has nested child items with overflow:hidden styles. Here is an example of the structure: <tr> <td id="targetid"> <div id="innertargetdiv"> ...

Why is my React component not updating after changing the state using Set State?

Uncovering the elusive problem seems impossible. Despite state changes, the component remains unrerendered. Here's the code: export const InterestsPupup: React.FC = ({interests, title, buttonText}) => { const [activeItems, setActiveItems] = useSt ...

Utilizing JavaScript to retrieve input names from arrays

This is the HTML form that I am currently working with: <form action="#" method="post"> <table> <tr> <td><label>Product:<label> <input type="text" /></td> <td><label>Price:<label> ...

Issue: The variable does not appear to be getting updated

After spending the last 2 hours analyzing this JS code, I am still unable to figure out why the variable "message" is not being changed to "User already exists." The bizarre thing is that the code block labeled "Inside first if" is executed, but the "mes ...

Retrieving output from ephemeral express server

I have a coding project where I need to authenticate externally with a service. My approach involves using express to handle the redirect and retrieve necessary data. However, my challenge lies in returning this data to the main scope. Here is the current ...

Div does not show global variable

In the beginning of my .js file, I define a variable like this: var selection = "example"; When I navigate from page 1.html to page 2.html by clicking a link, I have the following code on page 2.html: <script>document.write(selection);</script& ...

Is there a way to make the scrollbar-react component extend to full page width?

I'm currently in the process of developing a to-do application that consists of a sidebar and a page for listing tasks. My goal is to have the page fill the entire screen without specifying a fixed height. Would it be feasible to achieve this using s ...

Having trouble with passing parameters in AngularJS $state.go?

Having some trouble implementing AngularJS $state.go() with a parameter. It seems to work fine without the parameter, but when I try to pass one in, it's not working as expected. I've looked at several examples and tried different approaches, but ...

Can anyone recommend a good library for generating keywords for content?

Recently, I've been working on developing a CMS to use on my website. I'm curious if there are any free libraries out there that can help generate tags based on content. For example: I have a love for trees. Trees are amazing plants that show ...

What is the best way to extract plain text with JQuery?

I found this Html code snippet: <div class="form-group row"> <label id="lb_size" class="col-lg-3 col-form-label"> <span class="must-have">****</span> Size </label> </div> My goal is to ext ...

Deactivate the selection option for the radio button that is checked in a specific

I am attempting to deactivate the selection when any of the "color1, color2, or color3" buttons are chosen. I desire it to be activated only when the "color4" radio button is selected. After consulting various sources, integrating it into my code has left ...