Javascript webserver questions

Hi All,

I'm trying to put a refresh button onto my arduino webserver using the following code within the html code inside my sketch:

Reload I/O

I've attached an image of my code plus the code.

I have an auto refresh every 10 seconds but I'd really like to add a manual refreh button if possible.

I can't get it too work, any help would be really helpful!

Thanks
Iceni

WebsiteWithAnalog3.ino (9.09 KB)

Why do you think you can put Java script into your arduino C++ code? It won't be understood by the compiler. Also you don't want it there, do you? You want this to be part of the web page, so you need to just do what you did (copied without understanding ?) for the lines above - do a client.println of those lines so that they end up in the HTML sent to the browser

   // vvvvvvvvvvvvv
   // GET RID OF THIS LINE
   client.println("<script type='text/javascript'>"); 
   // ^^^^^^^^^^^
   client.println("<button onclick = "myFunction()">Reload I/O</button>");
   client.println("<script>");
   client.println("function myFunction() {");
   client.println("location.reload()");
   client.println("}");
   client.println("</script>");

Hi PaulMurrayCBr

Thanks for the reply, I really appreciate your help as I'm really a mechanical engineer just trying my hand at programming. I gave it a try but I'm still getting an error message (see attached), any ideas?

Iceni

When you have double quotes into a string they need to be escaped with \

client.println("<button onclick = [color=red][b]\[/b][/color]"myFunction()[color=red][b]\[/b][/color]">Reload I/O</button>");

Thanks J-M-L

Just gave it a try and it compiled fine :slight_smile:

I'll give it a try on my Uno when I get home from work.

Thanks again

Iceni