Webswitch programing?

Hi guys,
how should i incorporate javascript into arduino ? I realy don’t know how to merge javascript language and that of the arduino.

I try this one :

            plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<script> "));

this one :

<SCRIPT language="Javascript" src="http://www.yoursite.com/yourfile.js">

this one :

<SCRIPT> 
var now;

function showMilitaryTime() { 
     if (document.theForm.showMilitary[0].checked) { 
          return true; 
     } 
     return false; 
} 

function showTheHours(theHour) { 
     if (showMilitaryTime() || (theHour > 0 && theHour < 13)) { 
          return (theHour); 
     } 
     if (theHour == 0) { 
          return (12); 
     } 
     return (theHour - 12); 
} 

function showZeroFilled(inValue) { 
     if (inValue > 9) { 
          return ":" + inValue; 
     } 
     return ":0" + inValue; 
} 

function showAmPm() { 
     if (showMilitaryTime()) { 
          return (""); 
     } 
     if (now.getHours() < 12) { 
          return (" am"); 
     } 
     return (" pm"); 
} 

function showTheTime() { 
     now = new Date(); 
     document.theForm.showTime.value =
     showTheHours(now.getHours()) +
     showZeroFilled(now.getMinutes()) +
     showZeroFilled(now.getSeconds()) +
     showAmPm(); 
     setTimeout("showTheTime()", 1000); 
} 

</SCRIPT>

<BODY onLoad="showTheTime();">

<FORM NAME="theForm"> 
     <INPUT TYPE="TEXT" NAME="showTime"> 
     Display Military Time? 
     <INPUT TYPE="RADIO" NAME="showMilitary" CHECKED>Yes 
     <INPUT TYPE="RADIO" NAME="showMilitary">No 
</FORM>

Can you help me? Google can’t.

Hanrun: Can you help me? Google can't.

I don't think anyone can help you... :\

            plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<script> "));

This statement sends some data to the requesting client. It identifies that a script definition is to start.

You must follow this with more statements to output the rest of the script.

The script will then be executed at the appropriate time by the client.

PaulS:

            plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<script> "));

This statement sends some data to the requesting client. It identifies that a script definition is to start.

You must follow this with more statements to output the rest of the script.

The script will then be executed at the appropriate time by the client.

okay so how can i incorporate this code ( it is a simple clock ) :

<SCRIPT> 
var now;

function showMilitaryTime() { 
     if (document.theForm.showMilitary[0].checked) { 
          return true; 
     } 
     return false; 
} 

function showTheHours(theHour) { 
     if (showMilitaryTime() || (theHour > 0 && theHour < 13)) { 
          return (theHour); 
     } 
     if (theHour == 0) { 
          return (12); 
     } 
     return (theHour - 12); 
} 

function showZeroFilled(inValue) { 
     if (inValue > 9) { 
          return ":" + inValue; 
     } 
     return ":0" + inValue; 
} 

function showAmPm() { 
     if (showMilitaryTime()) { 
          return (""); 
     } 
     if (now.getHours() < 12) { 
          return (" am"); 
     } 
     return (" pm"); 
} 

function showTheTime() { 
     now = new Date(); 
     document.theForm.showTime.value =
     showTheHours(now.getHours()) +
     showZeroFilled(now.getMinutes()) +
     showZeroFilled(now.getSeconds()) +
     showAmPm(); 
     setTimeout("showTheTime()", 1000); 
} 

</SCRIPT>

<BODY onLoad="showTheTime();">

<FORM NAME="theForm"> 
     <INPUT TYPE="TEXT" NAME="showTime"> 
     Display Military Time? 
     <INPUT TYPE="RADIO" NAME="showMilitary" CHECKED>Yes 
     <INPUT TYPE="RADIO" NAME="showMilitary">No 
</FORM>

If i’m right, i need to start with :
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<script> "));?

If i’m right, i need to start with :

Yes. Then, you need to send the rest of the lines the same way.

            plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<script>"));
            plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<var now;> "));
            plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("function showMilitaryTime() {  "));
// a whole bunch more lines
            plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</script>"));
// The rest of the data (the form itself) gets sent here

I have an error here

    plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<script>"));
    plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<var now;> "));
    plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("function showMilitaryTime()   "));








{if (document.theForm.showMilitary[0].checked) {       









    return true; 
     } 
     return false; 
} 

function showTheHours(theHour) { 
     if (showMilitaryTime() || (theHour > 0 && theHour < 13)) { 
          return (theHour); 
     } 
     if (theHour == 0) { 
          return (12); 
     } 
     return (theHour - 12); 
} 

function showZeroFilled(inValue) { 
     if (inValue > 9) { 
          return ":" + inValue; 
     } 
     return ":0" + inValue; 
} 

function showAmPm() { 
     if (showMilitaryTime()) { 
          return (""); 
     } 
     if (now.getHours() < 12) { 
          return (" am"); 
     } 
     return (" pm"); 
} 

function showTheTime() { 
     now = new Date(); 
     document.theForm.showTime.value =
     showTheHours(now.getHours()) +
     showZeroFilled(now.getMinutes()) +
     showZeroFilled(now.getSeconds()) +
     showAmPm(); 
     setTimeout("showTheTime()", 1000); 
} 


            plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</script>"));

            
            
    </SCRIPT>

<BODY onLoad="showTheTime();">

<FORM NAME="theForm"> 
     <INPUT TYPE="TEXT" NAME="showTime"> 
     Display Military Time? 
     <INPUT TYPE="RADIO" NAME="showMilitary" CHECKED>Yes 
     <INPUT TYPE="RADIO" NAME="showMilitary">No 
</FORM>

{if (document.theForm.showMilitary[0].checked) {

thios line

If you want anyone to tell you what is causing the error, you will have to show us what the error message is.

At a guess, you have got a fragment of JavaScript code that is supposed to be included in your HTML output stream, and you have got it plonked in the middle of your sketch as if it was processing code.

arduino_okay_novembre_2011.cpp: In function 'uint16_t print_webpage(uint8_t*, byte, byte, byte)':
_3_test:261: error: 'document' was not declared in this scope
_3_test:267: error: 'function' was not declared in this scope
_3_test:267: error: expected `;' before 'showTheHours'
_3_test:398: error: expected `}' at end of input

You probably need to post the javascript you are trying to enbed in a web page. Some of your javascript is probably being interpeted by the arduino compiler as arduino code instead of just text.

You can't just paste lines from your java script into the Arduino code. You need to send that java script line to the client using plen=es.ES_fill_tcp_data_p().

Why aren't you paying any attention?

You can't just paste lines from your java script into the Arduino code. You need to send that java script line to the client using plen=es.ES_fill_tcp_data_p(). 

Why aren't you paying any attention?

Sry but i don't understand the arduino language. I only know some basics law, not more.

What did you mean?

You probably need to post the javascript you are trying to enbed in a web page. Some of your javascript is probably being interpeted by the arduino compiler as arduino code instead of just text.

Sry but i don't understand the arduino language. I only know some basics law, not more.

Head over to Gigs and Collaborations, then. Offer to pay someone to write the code for you. I've already done 90% of the work. It isn't rocket science to look at the changes that have been made to your code that doesn't compile, and see how to change the rest of the code.

If you won't (not can't) do it, then you'll need to pay someone else to do it.

i don't want to pay someone for, i wish to understand why. I will try an other thing tonigh. I try to copy and past codes i found but there is always an error or something wrong. Maybe because i use enc28j60 rather than w5100. Anyway thx for helps and i will try some codes and post it here and maybe someone will see my error.

and maybe someone will see my error.

We've already seen your error, and told you what YOU need to do to fix it. You ignored that advice.