js variable change HTML

253
June 01, 2017, at 2:25 PM

i'm wanting to display "ON" when a variable $CS1 = 10 (this variable is successfully pulled from a database). If is pressed it rewrites values to database and writes "ON" (or "OFF). That bit works it's just when first loading up the page i want the 'ON' or 'OFF' to be associated with the $CS1 variable

++++++

<input onclick="control()" type="button" value="Switch" id="system">
  <p style="font-size:60px;" id="system" onclick="control()"></p>
</input>
<script>
  if ($CS1 = 10) {        
    x.style.color = red;
    document.getElementById("system").innerHTML = "ON"
  } else {
    x.style.color = black;
    document.getElementById("system").innerHTML = "OFF";
  }     
</script>
<script>
function control() {
  var black = 'rgb(0, 0, 0)';
  var red = 'rgb(255, 0, 0)';   
  var x = document.getElementById("system");
  var currentColor = window.getComputedStyle(x, null).color;
  if (currentColor === black) {
    $.get("turnon_s.php");
    x.style.color = red;
    document.getElementById("system").innerHTML = "ON";        
  } else {
    $.get("turnoff_s.php");
    x.style.color = black;
    document.getElementById("system").innerHTML = "OFF";
  } 
}
</script>
READ ALSO
Check if array value exist in another array, if not, replace with another value

Check if array value exist in another array, if not, replace with another value

I have here two arraysI've echoed it using json_encode():

192
Add/Update data in specific row of CSV file

Add/Update data in specific row of CSV file

I developed a program - a data matcher of two CSV fileSample input of the data in CSV file is below

188
Could not fetch data from Database using MySQL query on website

Could not fetch data from Database using MySQL query on website

I have website coded in php with mysql databaseIt running well on local server on my pc localhost but when i uploaded to hosting server(godaddy), it not fetch any data from database and not showing any data on my live website

222