Jump to content
Sign in to follow this  
s_avinash_s

value from getelementbyid

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

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...