WebServer + JS

Hello all!

I have a problem with my web server for home automation. I try read switch input and display on my website.. and its works (ON / OFF).

I used this code:

var count;

var num_an = this.responseXML.getElementsByTagName('switch').length;
for (count = 0; count < num_an; count++) {
document.getElementsByClassName("doors")[count].innerHTML =
this.responseXML.getElementsByTagName('switch')[count].childNodes[0].nodeValue;

}

and my arduino get:

    // read switches

for (count = 0; count < 3; count++) {
       cl.print("");
       if (digitalRead(sw_arr[count])) {
           cl.print("OFF");
       }
       else {
           cl.print("ON");
       }
       cl.println("");
   }

When I push the button i get on my website -> "ON", but i would like to get for example background red color for my div?
How can i do this?

I dont know how to change words to colors

Synaesthesia

Hehe,

Yeah sorry but my english isn't very good and i dont know how to "transfer" my thoughts :smiley:

Ok, so...

When I push the button i get on my website -> "ON", but i would like to get for example background red color for my div?
How can i do this?

I tried this code, but not results..

 for (count = 0; count < 3; count++) {
        cl.print("<switch>");
        if (digitalRead(sw_arr[count])) {
            client.println("<script>");
            client.println("$('.doors').css('background', 'blue');");
            client.println("</script>");
        }
        else {
           ...
        }
        cl.println("</switch>");
    }
            client.println("<script>");
            client.println("$('.doors').css('background', 'blue');");
            client.println("</script>");

Why are putting this in script tags?

What does this have to do with the Arduino? NOTHING! Your issues is STRICTLY an html/style sheet issue.

Easy, I am beginner...

I would like to only change text to background color when arduino read switch...

I have 4 doors.. and i read state from pins and display on my web server (website).
I received data from arduino and I dont know how to change on website.