Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Javascript - Che cosa c'è che non va con il mio codice?
Forum - Javascript - Che cosa c'è che non va con il mio codice?

Avatar
felixiuc91 (Normal User)
Rookie


Messaggi: 27
Iscritto: 16/04/2010

Segnala al moderatore
Postato alle 14:14
Giovedì, 22/03/2012
salve sto creando la tabellina di Pitagora (n x n) con una matrice, però non mi parte il codice al click seppure i passaggi logici sono giusti
Codice sorgente - presumibilmente Delphi

  1. <html>
  2.  <head>
  3.   <title>Tabellina pitagorica</title>
  4.    </head>
  5.    <BODY>
  6.    <form name="tabellina">
  7.    <TABLE>
  8.     <TR>
  9.       <INPUT TYPE="Button" NAME="Tira" VALUE=" Calcola " onClick="Lancia()">
  10.       <INPUT TYPE="RESET" VALUE="CANCELLA" NAME="B2" >
  11.           <INPUT TYPE="TEXT" SIZE=10 NAME="display" value="0"><BR>
  12.     </TR>
  13.    </TABLE>
  14.  <Script language="JavaScript">
  15. function Lancia()
  16. {
  17.    var i;
  18.    var j;
  19.    var c;
  20.    i=tabellina.display.value;
  21.    arr = new Array (i);
  22.    for (j = 0; j < i; ++ j)
  23.    {
  24.            arr [j] = new Array (i);
  25.    }
  26.    for (j = 0; j <= i; ++ j)
  27.    {
  28.       for (c = 0; c <= i; ++ c)
  29.           {
  30.              arr [j] [c] = (j)*(c) ;
  31.       }
  32.    }
  33.    document . writeln ("<table border>");
  34.    var row;
  35.    for (row = 0; row < arr . length; ++ row)
  36.    {
  37.           document . writeln (" <tr>");
  38.           var col;
  39.           for (col = 0; col < arr [row] . length; ++ col){
  40.           document . writeln ("  <td>" + arr [row] [col] + "</td>");
  41.           document . writeln (" </tr>");}
  42.    }
  43.    document . writeln ("</table>");
  44.    document . writeln (arr [2] [2]);
  45. }
  46. </script>
  47.   </form>
  48.  </body>
  49. </html>


Ultima modifica effettuata da felixiuc91 il 22/03/2012 alle 14:15
PM Quote
Avatar
signore del tempo (Normal User)
Newbie


Messaggi: 11
Iscritto: 20/03/2012

Segnala al moderatore
Postato alle 14:59
Giovedì, 22/03/2012
Prova così:
Codice sorgente - presumibilmente Delphi

  1. <html>
  2.  <head>
  3.   <title>Tabellina pitagorica</title>
  4.    </head>
  5.    <BODY>
  6.    <form name="tabellina">
  7.    <TABLE>
  8.     <TR>
  9.       <INPUT TYPE="Button" NAME="Tira" VALUE=" Calcola " onClick="Lancia()">
  10.       <INPUT TYPE="RESET" VALUE="CANCELLA" NAME="B2" >
  11.           <INPUT TYPE="TEXT" SIZE=10 NAME="display" value="0"><BR>
  12.     </TR>
  13.    </TABLE>
  14.  <Script language="JavaScript">
  15. window.onload=function(){
  16. function Lancia()
  17. {
  18.    var i;
  19.    var j;
  20.    var c;
  21.    i=tabellina.display.value;
  22.    arr = new Array (i);
  23.    for (j = 0; j < i; ++ j)
  24.    {
  25.            arr [j] = new Array (i);
  26.    }
  27.    for (j = 0; j <= i; ++ j)
  28.    {
  29.       for (c = 0; c <= i; ++ c)
  30.           {
  31.              arr [j] [c] = (j)*(c) ;
  32.       }
  33.    }
  34.    document . writeln ("<table border>");
  35.    var row;
  36.    for (row = 0; row < arr . length; ++ row)
  37.    {
  38.           document . writeln (" <tr>");
  39.           var col;
  40.           for (col = 0; col < arr [row] . length; ++ col){
  41.           document . writeln ("  <td>" + arr [row] [col] + "</td>");
  42.           document . writeln (" </tr>");}
  43.    }
  44.    document . writeln ("</table>");
  45.    document . writeln (arr [2] [2]);
  46. }
  47. }
  48. </script>
  49.   </form>
  50.  </body>
  51. </html>


PM Quote
Avatar
felixiuc91 (Normal User)
Rookie


Messaggi: 27
Iscritto: 16/04/2010

Segnala al moderatore
Postato alle 15:09
Giovedì, 22/03/2012
risolto: ho scritto
Codice sorgente - presumibilmente Plain Text

  1. arr [j] [c] = j * c

a quanto pare mi sono dimenticato lo spazio ai margini del per

PM Quote