Webserver-HTML button positioning and styles problem

Hello everyone! I'm newbie here!

I created a webserver on a arduino for my project on robotic car. At first I don't have any problems occurring on running the webserver but when i try to edit the button styles and it's positioning the webserver won't load "The webpage taking too long to load". Their is no problem when I try to run it on a simple button code without the styles and positioning but when I copied it to my arduino server, it won't load. I'm guessing I just fail to add something or my codes were have something excessive used of symbols. If anyone could help me on button positioning and styles...

Below is the html code of my webserver

void loop() {
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {   
      if (client.available()) {
        char c = client.read();
     
        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string
          readString += c;
          //Serial.print(c);
         }

         //if HTTP request has ended
         if (c == '\n') {          
           Serial.println(readString); //print to serial monitor for debuging
     
           client.println("HTTP/1.1 200 OK"); //send new page
           client.println("Content-Type: text/html");
           client.println();     
           client.println("<HTML>");
           client.println("<BODY style='background-color:black'>");
           client.println("<font style='color:green'>");
           client.println("<font style='font-family:electric toaster'>");
           client.println("<center>");
           client.println("<H1 style='font-size:400%;'>Design Project (DP)</H1>");
           client.println("<p style='font-size:150%'>Surveillance Robotic Car</p>");
           client.println("
");
           client.println("
");   
           client.println("
");     
           client.println("<strong>");
           client.println("<div style='position:absolute; top:360px; left:466px; font-size:125%; font-family:robotastic;'>Live Video Feed and Sound</div>
");
           client.println("</strong>");     
           client.println("<iframe src='http://192.168.0.100' width='420' height='300' seamless scrolling='yes'></iframe>");
           client.println("</center>");
           client.println("<strong>");
           client.println("<div style='position:absolute; top:360px; left:76px; font-size:125%; font-family:robotastic;'>Controls for the</div>");
           client.println("div style='position:absolute; top:378px; left:126px; font-size:125%; font-family:robotastic;'>Robotic Car</div>"); 
           client.println("</strong>");
           client.println("<a href=\"/?buttonmotorforward\"\"><button style='font-size:170%;background-color:darkgray; color:green; border-radius:50px; position:absolute; top:430px; left:166px;'>Forward</button></a>");  
           client.println("<a href=\"/?buttonmotorleft\"\"><button style='font-size:170%; background-color:darkgray; color:green;border-radius:50px; position:absolute; top:530px; left:15px;'>Turn Left</button></a>"); 
           client.println("<a href=\"/?buttonmotorstop\"\"><button style='font-size:170%; background-color:darkgray; color:green;border-radius:50px; position:absolute; top:530px; left:188px;'>Stop</button></a>");
           client.println("<a href=\"/?buttonmotorright\"\"><button style='font-size:170%; background-color:darkgray; color:green;border-radius:50px; position:absolute; top:530px; left:300px;'>Turn Right</button></a>");
           client.println("<a href=\"/?buttonmotorbackward\"\"><button style='font-size:170%; background-color:darkgray; color:green; border-radius:50px; position:absolute; top:630px; left:156px;'>Backward</button></a>");
           client.println("<a href=\"/?buttonledon\"\"><button style='font-size:100%; background-color:darkgray; color:green;border-radius:50px; position:absolute; top:640px; left:16px;'>TurnON Lights</button></a>");
           client.println("<a href=\"/?buttonledoff\"\"><button style='font-size:100%; background-color:darkgray; color:green;border-radius:50px; position:absolute; top:640px; left:310px;'>TurnOff Lights</button></a>");
           client.println("</BODY>");
           client.println("</HTML>");
           
           delay(1);
           //stopping client
           client.stop();
           //controls the Arduino if you press the buttons
           if (readString.indexOf("?buttonledon") >0){
               digitalWrite(led1, HIGH);
           }
           if (readString.indexOf("?buttonledoff") >0){
               digitalWrite(led1, LOW);
           }
           if (readString.indexOf("?buttonmotorforward") >0){
               digitalWrite(led2, LOW);                      //tell the led to turn on when car turn forward
           }
           if (readString.indexOf("?buttonmotorstop") >0){
               digitalWrite(led2, HIGH);                      //tell the led to turn on when car stop
           }
           if (readString.indexOf("?buttonmotorleft") >0){    
               digitalWrite(led2, LOW);                      //tell the led to turn off when car turn left
           }
           if (readString.indexOf("?buttonmotorright") >0){
               digitalWrite(led2, LOW);                      //tell the led to turn off when car turn right
           }
           if (readString.indexOf("?buttonmotorbackward") >0){
               digitalWrite(led2, LOW);                      //tell the led to turn off when car turn backward
           }
           if (readString.indexOf("?buttonmotorforward") >0){    //tell car to turn forward
                //for(pos = 0; pos <=180; pos += 3)  // goes from 0 degrees to 180 degrees 
                {                                  // in steps of 1 degree 
                  servoleft.write(180);            // tell the left servo to go left position  
                  delay(15);                       // waits 15ms for the servo to reach the position 
                  servoright.write(0);            // tell the right servo to go to right position  
                  delay(15);          
                } 
           }
           if (readString.indexOf("?buttonmotorbackward") >0){    //tell car to turn backward
                //for(pos = 180; pos>=0; pos-=3)     // goes from 180 degrees to 0 degrees 
                {                                
                  servoleft.write(0);              // tell the left servo to go right position
                  delay(15);                       // waits 15ms for the servo to reach the position 
                  servoright.write(180);          // tell the right servo to go to left position 
                  delay(15);  
                } 
           }
           if (readString.indexOf("?buttonmotorstop") >0){    //tell the car to stop
                //for(pos = 180; pos>=0; pos-=3)     // goes from 180 degrees to 0 degrees 
                {                                
                  servoleft.write(90);              // tell the left servo to go to no movement position  
                  delay(15);                       // waits 15ms for the servo to reach the position 
                  servoright.write(90);          // tell the right servo to go to no movement position  
                  delay(15);  
                } 
           }
           if (readString.indexOf("?buttonmotorleft") >0){    //tell the car to turn left
                //for(pos = 0; pos <=180; pos += 3)  // goes from 0 degrees to 180 degrees 
                {                                  // in steps of 1 degree 
                  servoleft.write(90);            // tell the left servo to go left position  
                  delay(15);                       // waits 15ms for the servo to reach the position 
                  servoright.write(0);            // tell the right servo to go to no movement position  
                  delay(15);          
                } 
           }
           if (readString.indexOf("?buttonmotorright") >0){  //tell the car to turn right
                //for(pos = 0; pos <=180; pos += 3)  // goes from 0 degrees to 180 degrees 
                {                                  // in steps of 1 degree 
                  servoleft.write(180);            // tell the left servo to go left position  
                  delay(15);                       // waits 15ms for the servo to reach the position 
                  servoright.write(90);            // tell the right servo to go to no movement position 
                  delay(15);          
                } 
           }
            //clearing string for next read
            readString="";  
           
         }
       }
    }
}
}

You are probably running out of memory with all the static html lines. Try putting your web page inside an F() macro like below.

//get submit box code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html or use a '
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

String readString;

//////////////////////

void setup(){

 pinMode(5, OUTPUT); //pin selected to control
 pinMode(6, OUTPUT); //pin selected to control
 pinMode(7, OUTPUT); //pin selected to control
 pinMode(8, OUTPUT); //pin selected to control
 //start Ethernet
 Ethernet.begin(mac, ip, gateway, gateway, subnet);
 server.begin();

 //enable serial data print
 Serial.begin(9600);
 Serial.println(F("server text box test1")); // so I can keep track of what is loaded
}

void loop(){
 // Create a client connection
 EthernetClient client = server.available();
 if (client) {
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();

       //read char by char HTTP request
       if (readString.length() < 100) {

         //store characters to string
         readString += c;
         //Serial.print(c);
       }

       //if HTTP request has ended
       if (c == '\n') {

         ///////////////
         Serial.println(readString); //see what was captured

         //now output HTML data header

client.print(F(  //start F() macro
"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"
"<HTML>"
"<HEAD>"
"<meta name='apple-mobile-web-app-capable' content='yes' />"
"<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />"
"<TITLE>JAVA Page</TITLE>"
"</HEAD>"
"<BODY>"
"<H1>JAVA</H1>"
"<hr />"
"
"
"<FORM ACTION='/' method=get >"
"Enter Code: <INPUT TYPE=TEXT NAME='LED' VALUE='' SIZE='25' MAXLENGTH='50'>
"
"
"
"<input type=submit value='5 ON' style=width:100px;height:45px onClick=location.href='/?on8;'><input type=submit value='5 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>
"
"<input type=submit value='6 ON' style=width:100px;height:45px onClick=location.href='/?on8;'><input type=submit value='6 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>
"
"<input type=submit value='7 ON' style=width:100px;height:45px onClick=location.href='/?on8;'><input type=submit value='7 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>
"
"<input type=submit value='8 ON' style=width:100px;height:45px onClick=location.href='/?on8;'><input type=submit value='8 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>
"
"</FORM>"
"</BODY>"
"</HTML>"
));   //end F() macro

         delay(1);
         //stopping client
         client.stop();

         /////////////////////
         if(readString.indexOf("5") >0)//checks for on
         {
           digitalWrite(5, HIGH);    // set pin 5 high
           Serial.println(F("Led On"));
         }
         if(readString.indexOf("50") >0)//checks for off
         {
           digitalWrite(5, LOW);    // set pin 5 low
           Serial.println(F("Led Off"));
         }
         
         if(readString.indexOf("6") >0)//checks for on
         {
           digitalWrite(6, HIGH);    // set pin 6 high
           Serial.println(F("Led 6 On"));
         }
         if(readString.indexOf("60") >0)//checks for off
         {
           digitalWrite(6, LOW);    // set pin 6 low
           Serial.println(F("Led 6 Off"));
         }
         
         if(readString.indexOf("7") >0)//checks for on
         {
           digitalWrite(7, HIGH);    // set pin 7 high
           Serial.println(F("Led On"));
         }
         if(readString.indexOf("70") >0)//checks for off
         {
           digitalWrite(7, LOW);    // set pin 7 low
           Serial.println(F("Led Off"));
         }
         
         if(readString.indexOf("8") >0)//checks for on
         {
           digitalWrite(8, HIGH);    // set pin 8 high
           Serial.println(F("Led On"));
         }
         if(readString.indexOf("80") >0)//checks for off
         {
           digitalWrite(8, LOW);    // set pin 8 low
           Serial.println(F("Led Off"));
         }
         //clearing string for next read
         readString="";

       }
     }
   }
 }
}

You are grace from heaven zoomkat. Thank you very much on your suggestion, I am now able to edit styles and positioning on my buttons. But i have another problem, why does the webpage always refreshing whenever I pressed buttons? It gives delays on the output because the led only lights when the webpage finished refreshing. How can I get rid of that?

But i have another problem, why does the webpage always refreshing whenever I pressed buttons?

Because that is the way your server code is designed. In your code a new page is sent back to the browser no matter what is sent to the server. In the below server test code a "?" is looked for in the incoming request. A command will always have the "?" in it, which will result in the no refresh status code 204 being sent back to the browser to prevent loading a new page. If the "?" is not present in what the server receives, a new page is sent back to the browser.

//zoomkat 10-6-13
//simple button GET with iframe code
//open serial monitor to see what the arduino receives
//use the ' instead of " in html ilnes 
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //ethernet shield mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino IP in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

String readString; 

//////////////////////

void setup(){

  pinMode(4, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("servertest1"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

          //now output HTML data header
             if(readString.indexOf('?') >=0) { //don't send new page
               client.println("HTTP/1.1 204 Zoomkat");
               client.println();
               client.println();  
             }
             else {
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
          
          client.println("<a href='/?on1' target='inlineframe'>ON</a>"); 
          client.println("<a href='/?off' target='inlineframe'>OFF</a>"); 

          client.println("<IFRAME name=inlineframe style='display:none'>");          
          client.println("</IFRAME>");

          client.println("</BODY>");
          client.println("</HTML>");
             }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on1") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

But I already have used ? in commands

see the codes

           "<a href=\"/?buttonmotorforward\"\"><button style='font-size:170%;background-color:darkgray; color:green; border-radius:50px; position:absolute; top:430px; left:166px;'>Forward</button></a>"
           "<a href=\"/?buttonmotorleft\"\"><button style='font-size:170%; background-color:darkgray; color:green;border-radius:50px; position:absolute; top:530px; left:15px;'>Turn Left</button></a>"
           "<a href=\"/?buttonmotorstop\"\"><button style='font-size:170%; background-color:darkgray; color:green;border-radius:50px; position:absolute; top:530px; left:188px;'>Stop</button></a>"
           "<a href=\"/?buttonmotorright\"\"><button style='font-size:170%; background-color:darkgray; color:green;border-radius:50px; position:absolute; top:530px; left:300px;'>Turn Right</button></a>"
           "<a href=\"/?buttonmotorbackward\"\"><button style='font-size:170%; background-color:darkgray; color:green; border-radius:50px; position:absolute; top:630px; left:156px;'>Backward</button></a>"
           "<strong>"

But I already have used ? in commands

You need to read post #3 and look at the associated code.

Oh I see now. Sorry for the very late response, I'm having a short christmas vacation with my family. By the way I see the needed code to be added

               if(readString.indexOf('?') >=0) { //don't send new page
               client.println("HTTP/1.1 204 Zoomkat");
               client.println();
               client.println();  
             }
             else
             


             }
 {

And now the webpage didn't refresh anymore. Thank you very much Zoomkat :smiley: You're my savior

You Need to make each of the Button Variables Different. See enclosed. This Works Fine
/*
Workin Simple WebServer for House Stero

*/

#include <SPI.h>
#include <EthernetV2_0.h>

int Zone1 = 5;
int Zone2 = 6;
int Zone3 = 7;
int Zone4 = 8;

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEf };
IPAddress ip(192,168,1, 178);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
IPAddress dnServer(192,168,1,1);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
#define W5200_CS 10
#define SDCARD_CS 4

String readString;
void setup() {
delay( 3000 ); // Gives time for eithernet card to stabilize
// Open serial communications and wait for port to open:
Serial.begin(9600);
pinMode(SDCARD_CS,OUTPUT);
digitalWrite(SDCARD_CS,HIGH);//Deselect the SD card
pinMode(Zone1, OUTPUT);
pinMode(Zone2, OUTPUT);
pinMode(Zone3, OUTPUT);
pinMode(Zone4, OUTPUT);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, dnServer, gateway, subnet);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}

void loop() {
// Create a client connection
EthernetClient client = server.available();

if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}

//if HTTP request has ended
if (c == '\n') {

Serial.println(readString); //print to serial monitor for debuging

client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("");
client.println("");
client.println("");
// Header
client.println("");
client.println("Dons Home Stero");

//Body
client.println("");
client.println("

");
client.println("");
client.println("


"); client.println("

Don's Stero Control

"); client.println("
"); client.println(" "); client.println("

Amplifier Zone Control

"); client.println(" "); client.println("Living Room On"); client.println("Living Room Off"); client.println(" "); client.println(" "); client.println("Dining Room On"); client.println("Dining Room Off"); client.println(" "); client.println(" "); client.println("Outside Deck On"); client.println("Outside Deck Off"); client.println(" "); client.println(" "); client.println("Master Bed Room On"); client.println("Master Bed Room Off");

//client.println("

Created by Don Davidson

");
client.println("
");
client.println("");
client.println("");
delay(2);

//controls the Arduino if you press the buttons
if (readString.indexOf("?button1on") >0){
digitalWrite(Zone1, HIGH);
}
if (readString.indexOf("?button1off") >0){
digitalWrite(Zone1, LOW);
}
if (readString.indexOf("?button2on") >0){
digitalWrite(Zone2, HIGH);
}
if (readString.indexOf("?button2off") >0){
digitalWrite(Zone2, LOW);
}
if (readString.indexOf("?button3on") >0){
digitalWrite(Zone3, HIGH);
}
if (readString.indexOf("?button3off") >0){
digitalWrite(Zone3, LOW);
}
if (readString.indexOf("?button4on") >0){
digitalWrite(Zone4, HIGH);
}
if (readString.indexOf("?button4off") >0){
digitalWrite(Zone4, LOW);
}

if (digitalRead(Zone1) == 1) { client.println("<a href="/?button1on"">Living Room On");}
if (digitalRead(Zone2) == 1) { client.println("<a href="/?button2on"">Dining Room On");}
if (digitalRead(Zone3) == 1) { client.println("<a href="/?button3on"">Outside Deck On");}
if (digitalRead(Zone4) == 1) { client.println("<a href="/?button4on"">Master Bed Room On");}
delay(2);
client.stop();
//clearing string for next read
readString="";

}
}
}
}
}