Jump to content

value from getelementbyid


s_avinash_s

Recommended Posts

Hi,

I am using a following code.

<p  id="error_pos1a"></p>
     
    <script>
    function error_1() {
        var x;
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() 
      {
            if (this.readyState == 4 )
            {
                if(xhttp.status == 0) 
                {      
                    
                }
                else 
                {                        
                    document.getElementById("error_pos1a").innerHTML = this.responseText;        
                    x=   document.getElementById("error_pos1a").innerHTML;  
                    if (x == 0 )
                     {
                        document.getElementById("error_pos1a").innerHTML = "Tube Not Full";
                     }
                     else
                     {
                        document.getElementById("error_pos1a").innerHTML = "Tube  Full";
                     }
                }
            }       
      };
    xhttp.open("GET", "error_val1.txt", true);
    xhttp.send();
    }

    setInterval(error_1(), 1000);
    </script>

Actually i need a clarification for "  x=   document.getElementById("error_pos1a").innerHTML; "

whether x gets the correct value by this

 

Link to comment
Share on other sites

https://www.w3schools.com/jsref/prop_html_innerhtml.asp

The innerHTML property just gets anything that's in between the tags specified in the selector.

Checking whether (x == 0) would only function if you had "0" inside your <p> tags.

 

Instead of updating the InnerHTML, comparing the innerHTML and then updating it again based on that.

Why don't you instead

x = this.responseText

and then continue as normal.

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...