So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By martinayotte
#63841 This button code will go to another page :
Code: Select all<input type='button' style='width:100px;height:30px' value='Page2' onClick='window.location.replace("/page2");'/><br>
User avatar
By potz
#65591 thanks for you answer but it's not clear for me how to insert the code for page 2 :

[code][/void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}

// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}

// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();

// Match the request

int value = LOW;
if (request.indexOf("/LED=ON") != -1) {
digitalWrite(ledPin, HIGH);
value = HIGH;
}
if (request.indexOf("/LED=OFF") != -1) {
digitalWrite(ledPin, LOW);
value = LOW;
}

// Set ledPin according to the request
//digitalWrite(ledPin, value);

// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");

client.print("Led pin is now: ");

if(value == HIGH) {
client.print("On");
} else {
client.print("Off");
}
client.println("<br><br>");

//I would like this on page 1
client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");


//I would like this on page 2
client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");


client.println("</html>");

delay(1);
Serial.println("Client disonnected");
Serial.println("");

}
code]
thanks
User avatar
By atexit8
#65737 Do you need a second page?

It seems that depending on the value of a variable, you will want to have if-else
Code: Select allclient.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");

or
Code: Select allclient.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");