s_avinash_s Posted October 4, 2018 Share Posted October 4, 2018 (edited) Hi I have a below code which works perfectly when Ethernet cable is connected or disconnected. <p id="ping1"> </p> <script> function ping() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if(xhttp.readyState == 4) { if(xhttp.status == 0) { document.getElementById("ping1").innerHTML = "Disconnected"; document.getElementById("ping1").style.color = "red"; } else { document.getElementById("ping1").innerHTML = "Connected"; document.getElementById("ping1").style.color = "green"; } } }; xhttp.open("GET", "ping.txt", true); xhttp.send(); } setInterval(ping(), 1000); </script> Now i want to modify the below code if(xhttp.status == 0) { document.getElementById("ping1").innerHTML = "Disconnected"; document.getElementById("ping1").style.color = "red"; } else { document.getElementById("ping1").innerHTML = "Connected"; document.getElementById("ping1").style.color = "green"; } with a red button for disconnected and with green for connected.(button like small dot ). I got the below code for dots creation just need to change a color.But how to use in my code for xhttp.status == 0 and else part Please suggest a way to do it Edited October 4, 2018 by s_avinash_s Link to comment Share on other sites More sharing options...
s_avinash_s Posted October 8, 2018 Author Share Posted October 8, 2018 (edited) Hi I have got a sample code for LED change. https://www.w3schools.com/code/tryit.asp?filename=FW1SQNHXYORW How to get led change in below conditions using div as shown above. if(xhttp.status == 0) { document.getElementById("ping1").innerHTML = "Disconnected"; document.getElementById("ping1").style.color = "red"; } else { document.getElementById("ping1").innerHTML = "Connected"; document.getElementById("ping1").style.color = "green"; } In above if status is 0 , i need to glow yellow LED else Green .How to do it. Please help Edited October 8, 2018 by s_avinash_s Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now