two way communication between Arduino and a website

Hi all,

I have an arduino ethernet with arduino mega 2560. I managed to display a webpage contain a textbox and a button. As i really new to arduino and HTML, i am not sure whether i am writing properly for the code. I want to use javascript that return me the textbox’s value that being entered and also update the URL so my arduino can detect.
For example if I write a value 2 inside the text box and click the button, then in my HTML will display the current value become 2 which just next to the textbox and my URL will become http://192.98.40.2/?2.
I want to let the arduino know that the current value is 2 as well.

Here is my code:

client.println("<HTMLhead>");
         client.println("<body>");
         client.println("Motor <p>Please enter the value of motor     Current Value =checkForm() ");
         client.print("</p>");
         client.println("<form method=\"post\" action=\"http://");
         client.print(Domain);
         client.print("m\" onSubmit=\"return checkForm()\"><input type=\"text\"id=\"mtr\" /><input type=\"submit\" /></form>"); 
         client.println("<script type=\"text/javascript\"> function checkForm() { var MValue = document.getElementById(\"mtr\"); String mv; mv=   MValue.value; return mv;)}</script>");
      client.println("</body><html>");

Thanks in advance. Any help will really be appreciated!!!

I want to use javascript that return me the textbox's value that being entered and also update the URL so my arduino can detect.

You don't need javascript for this. The page should contain a form with a submit button. The action for the submit should be the same as the original request for the page. The submitted GET request will have ? and some other stuff appended, depending on the form field names and field contents.

Hi PaulS,

Thank you very much for your reply. As you said, I just realize that I don’t need javascript.
I also found a very good example by a smart guy Hari (here is the link in case anyone need it —> http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284844153) which give me a good start. But now i have problem as I need to read 2 to 3 digit as the command only allow to read 1 digit.

  //Received buffer contains "GET /cmd/param1/param2 HTTP/1.1".  Break it up.
  char* slash1;
  char* slash2;
  char* slash3;
  char* space2;
  
  slash1 = strstr(buffer, "/") + 1; // Look for first slash
  slash2 = strstr(slash1, "/") + 1; // second slash
  slash3 = strstr(slash2, "/") + 1; // third slash
  space2 = strstr(slash2, " ") + 1; // space after second slash (in case there is no third slash)
  if (slash3 > space2) slash3=slash2;

  PrintString("slash1",slash1);
  PrintString("slash2",slash2);
  PrintString("slash3",slash3);
  PrintString("space2",space2);
  
  // strncpy does not automatically add terminating zero, but strncat does! So start with blank string and concatenate.
  cmd[0] = 0;
  param1[0] = 0;
  param2[0] = 0;
  strncat(cmd, slash1, slash2-slash1-1);
  strncat(param1, slash2, slash3-slash2-1);
  strncat(param2, slash3, space2-slash3-1);
  
  PrintString("cmd",cmd);
  PrintString("param1",param1);
  PrintString("param2",param2);
}



{
   int analogPin = param1[0] - '0'; // Param1 should be one digit analog port <--- i need 2 or 3 digit
  int analogValue = analogRead(analogPin);
  
  //-- Send response back to browser --
  server.print("A");
  server.print(analogPin, DEC);
  server.print(" is ");
  server.print(analogValue,DEC);

Do you have any clue how to read 2 or 3 digit from parameter 1. Thank you in advance.

But now i have problem as I need to read 2 to 3 digit as the command only allow to read 1 digit.

What command?

Post all of your code, and some sample input.

Hi PaulS,

Once again, thanks for the reply. I managed to solve the problem -- the array problem . I didn't managed the array properly. Everything works now. Thank you very much for your help. Really appreciate it ^^. :)