Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Somma di due numeri presenti in un form

    Ciao,
    Vorrei sapere qual'è o quali sono gli errori in questa pagina; Il codice é:
    <html>
    <head>
    <title>Documento senza titolo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <?php
    function somma(form) {
    echo "Sto eseguendo la funzione";
    form.Somma.value()=form.Add1.value() + form.Add2.value();
    }
    ?>
    </head>

    <body>
    <form name="form" onClick="somma">
    Primo Addendo
    <input type="text" name="Add1" value="0" maxlength="5">


    Secondo Addendo
    <input type="text" name="Add2" value="0" maxlength="5">


    Totale
    <input type="text" name="Somma" disabled value="0" maxlength="6">
    <input type="submit" value="Somma">
    </form>
    </body>
    </html>
    Grazie, Ciaoooo
    Mikele

  2. #2
    roba di javascript....

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  3. #3
    Utente di HTML.it L'avatar di marco80
    Registrato dal
    May 2005
    Messaggi
    1,357
    Non sono esperto con javascript ma cmq nella funzione somma(fatta nel contesto php) devi passare una variabile e non FORM xche' non e' una funzione javascript cosi' com'e' scritta. Per javascript dovrebbe stare fra i tag <script> </script>
    Prova intanto a sistemare questo. E sull onclick se non error dovresti cmq mettere ="somma( e qui il valore da passare che sara' poi il valore di form che hai usato sopra)"

  4. #4
    Codice PHP:
    <html>
    <head>
    <title>Documento senza titolo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function somma(form) {
    document.write "Sto eseguendo la funzione";
    form.Somma.value=form.Add1.value() + form.Add2.value();
    }
    </script>
    </head>

    <body>
    <form name="form" onClick="somma()">
    Primo Addendo
    <input type="text" name="Add1" value="0" maxlength="5"> 
     

    Secondo Addendo
    <input type="text" name="Add2" value="0" maxlength="5"> 
     

    Totale
    <input type="text" name="Somma" disabled value="0" maxlength="6">
    <input type="submit" value="Somma">
    </form>
    </body>
    </html>

    se vuoi farlo in PHP..

    <html>
    <head>
    <title>Documento senza titolo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <?php
      
    if ($_REQUEST['id']) {
       
    $num1 $_POST['Add1'];
       
    $num2 $_POST['Add2'];
       echo 
    "la somma di $num1 + $num2 = ".$num1 $num2;
      }
    ?>
    </head>

    <body>
    <form name="form" method="post" action="pippo.php?id=1">
    Primo Addendo
    <input type="text" name="Add1" value="0" maxlength="5"> 
     

    Secondo Addendo
    <input type="text" name="Add2" value="0" maxlength="5"> 
     

    Totale
    <input type="text" name="Somma" disabled value="0" maxlength="6">
    <input type="submit" value="Somma">
    </form>
    </body>
    </html>

  5. #5
    Grazie per avermi risposto. Ma adesso, come faccio a far visualizzare il risultato della somma nel campo testo "Somma"? ciao
    Mikele

  6. #6
    Codice PHP:

    <html>
    <head>
    <title>Documento senza titolo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <form name="form" method="post" action="pippo.php?id=1">
    Primo Addendo
    <input type="text" name="Add1" value="0" maxlength="5" /> 
     

    Secondo Addendo
    <input type="text" name="Add2" value="0" maxlength="5" /> 
     

    Totale
    <input type="text" name="Somma" disabled value="0" maxlength="6" />
    <input type="submit" value="Somma" />
    <?php
      
    if ($_REQUEST['id']) {
       
    $num1 $_POST['Add1'];
       
    $num2 $_POST['Add2'];
       
    $somma $num1 num2
       echo 
    "<script type=\"text/javascript\">document.form.Somma.value=$somma</script>";
      }
    ?>
    </form>
    </body>
    </html>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.