Visualizzazione dei risultati da 1 a 10 su 10

Discussione: errore su una somma

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    583

    errore su una somma

    c'č un errore su una somma ecco il risultato




    <form name=somme>

    <script language="javascript">
    function somme() {
    somme.risultato.value=eval(somme.qclassicblack.val ue)+eval(somme.qclassicyellow.value)+eval(somme.qc lassicred.value)+eval(somme.qclassicorange.value)+ eval(somme.qclassicblue.value)+eval(somme.qclassic green.value)+eval(somme.qclassicwhite.value)+eval( somme.qclassicpurple.value)+eval(somme.qclassicsil ver.value)+eval(somme.qclassicneon.value)+eval(som me.qclassicexplorer.value);
    }
    </script>


    <tr>
    <td width="38" bgcolor="#000000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"> <input size="3" id="qclassicblack" type=text value="0" name="qclassicblack"></font></td>
    <td width="45" bgcolor="#FFFF00" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicyellow" type=text value="0" name="qclassicyellow"></font></td>
    <td width="30" bgcolor="#FF0000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicred" type=text value="0" name="qclassicred"></font></td>
    <td width="48" bgcolor="#FF8000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicorange" type=text value="0" name="qclassicorange"></font></td>
    <td width="32" bgcolor="#0000FF" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicblue" type=text value="0" name="qclassicblue"></font></td>
    <td width="38" bgcolor="#008000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicgreen" type=text value="0" name="qclassicgreen"></font></td>
    <td width="30" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicwhite" type=text value="0" name="qclassicwhite"></font></td>
    <td width="38" bgcolor="#800080" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicpurple" type=text value="0" name="qclassicpurple"></font></td>
    <td width="38" bgcolor="#C0C0C0" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicsilver" type=text value="0" name="qclassicsilver"></font></td>
    <td width="38" bgcolor="#CCFF00" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicneon" type=text value="0" name="qclassicneon"></font></td>
    <td width="50" height="60" background="explorer.gif" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicexplorer" type=text value="0" name="qclassicexplorer"></font></td>
    <td width="44" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" type="button" value="somme" onclick=somme()>
    <input type=text name="risultato">

    </font></td>
    </tr>

    </form>

  2. #2
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    ammesso che "somme" sia il nome del form (ti sconsiglio di usare lo stesso nome per un form e una funzione) devi mettere document.somme... e puoi togliere gli eval
    ma devi convertire il value a numeri con parseInt(document.somme...value) o parseFloat

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    583
    <form name=somme>

    <script language="javascript">
    function somma() {
    somma.risultato.value=parseFloat(somme.qclassicbla ck.value)+parseFloat(somme.qclassicyellow.value)+p arseFloat(somme.qclassicred.value)+parseFloat(somm e.qclassicorange.value)+parseFloat(somme.qclassicb lue.value)+parseFloat(somme.qclassicgreen.value)+p arseFloat(somme.qclassicwhite.value)+parseFloat(so mme.qclassicpurple.value)+parseFloat(somme.qclassi csilver.value)+parseFloat(somme.qclassicneon.value )+parseFloat(somme.qclassicexplorer.value);
    }
    </script>


    <tr>
    <td width="38" bgcolor="#000000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"> <input size="3" id="qclassicblack" type=text value="0" name="qclassicblack"></font></td>
    <td width="45" bgcolor="#FFFF00" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicyellow" type=text value="0" name="qclassicyellow"></font></td>
    <td width="30" bgcolor="#FF0000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicred" type=text value="0" name="qclassicred"></font></td>
    <td width="48" bgcolor="#FF8000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicorange" type=text value="0" name="qclassicorange"></font></td>
    <td width="32" bgcolor="#0000FF" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicblue" type=text value="0" name="qclassicblue"></font></td>
    <td width="38" bgcolor="#008000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicgreen" type=text value="0" name="qclassicgreen"></font></td>
    <td width="30" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicwhite" type=text value="0" name="qclassicwhite"></font></td>
    <td width="38" bgcolor="#800080" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicpurple" type=text value="0" name="qclassicpurple"></font></td>
    <td width="38" bgcolor="#C0C0C0" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicsilver" type=text value="0" name="qclassicsilver"></font></td>
    <td width="38" bgcolor="#CCFF00" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicneon" type=text value="0" name="qclassicneon"></font></td>
    <td width="50" height="60" background="explorer.gif" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicexplorer" type=text value="0" name="qclassicexplorer"></font></td>
    <td width="44" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" type="button" value="TOT" onclick=somma()>
    <input type=text name="risultato">

    </font></td>
    </tr>

    </form>


    Errore ancora ma non ho molto capito quello che volevi dirmi fammi sapere

  4. #4
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    codice:
    document.somma.risultato.value = parseFloat(document.somme.qclassicblack.value) + parseFloat(document.somme.qclassicyellow.value) + parseFloat(document.somme.qclassicred.value) + parseFloat(document.somme.qclassicorange.value) + parseFloat(document.somme.qclassicblue.value) + parseFloat(document.somme.qclassicgreen.value) + ...

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    583
    scusami ancora ma da errore
    ti ridico il codice


    <form name=somme>

    <script language="javascript">
    function somma() {

    document.somma.risultato.value = parseFloat(document.somme.qclassicblack.value) + parseFloat(document.somme.qclassicyellow.value) + parseFloat(document.somme.qclassicred.value) + parseFloat(document.somme.qclassicorange.value) + parseFloat(document.somme.qclassicblue.value) + parseFloat(document.somme.qclassicgreen.value) + parseFloat(document.somme.qclassicwhite.value) + parseFloat(document.somme.qclassicpurple.value) + parseFloat(document.somme.qclassicsilver.value) + parseFloat(document.somme.qclassicneon.value) + parseFloat(document.somme.qclassicexplorer.value) +

    }
    </script>


    <tr>
    <td width="38" bgcolor="#000000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"> <input size="3" id="qclassicblack" type=text value="0" name="qclassicblack"></font></td>
    <td width="45" bgcolor="#FFFF00" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicyellow" type=text value="0" name="qclassicyellow"></font></td>
    <td width="30" bgcolor="#FF0000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicred" type=text value="0" name="qclassicred"></font></td>
    <td width="48" bgcolor="#FF8000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicorange" type=text value="0" name="qclassicorange"></font></td>
    <td width="32" bgcolor="#0000FF" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicblue" type=text value="0" name="qclassicblue"></font></td>
    <td width="38" bgcolor="#008000" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicgreen" type=text value="0" name="qclassicgreen"></font></td>
    <td width="30" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicwhite" type=text value="0" name="qclassicwhite"></font></td>
    <td width="38" bgcolor="#800080" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicpurple" type=text value="0" name="qclassicpurple"></font></td>
    <td width="38" bgcolor="#C0C0C0" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicsilver" type=text value="0" name="qclassicsilver"></font></td>
    <td width="38" bgcolor="#CCFF00" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicneon" type=text value="0" name="qclassicneon"></font></td>
    <td width="50" height="60" background="explorer.gif" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" id="qclassicexplorer" type=text value="0" name="qclassicexplorer"></font></td>
    <td width="44" height="60" align="center"><font color="#800000" size="2" face="Tahoma"><input size="3" type="button" value="TOT" onclick="somma()">
    <input type="text" name="risultato">

    </font></td>
    </tr>

    </form>

    da errore quando clicco sul pulsante ciao

  6. #6
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    per come hai postato somma() non sembra finita
    che errore ti appare?

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    583
    errore in visualizzazione della pag in basso a sx

  8. #8
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    codice:
    document.somma.risultato.value = parseFloat(document.somme.qclassicblack.value) +
    parseFloat(document.somme.qclassicyellow.value) +
    parseFloat(document.somme.qclassicred.value) +
    parseFloat(document.somme.qclassicorange.value) +
    parseFloat(document.somme.qclassicblue.value) +
    parseFloat(document.somme.qclassicgreen.value) +
    parseFloat(document.somme.qclassicwhite.value) +
    parseFloat(document.somme.qclassicpurple.value) +
    parseFloat(document.somme.qclassicsilver.value) +
    parseFloat(document.somme.qclassicneon.value) +
    parseFloat(document.somme.qclassicexplorer.value);
    uno dei due č sbagliato, devi mettere il nome del form

  9. #9
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    583
    ora sto provando cosi ma niente




    <form name="f1">

    <script language="javascript">
    function somma() {


    document.f1.risultato.value = parseFloat(document.f1.qclassicblack.value) +
    parseFloat(document.f1.qclassicyellow.value) +
    parseFloat(document.f1.qclassicred.value) +
    parseFloat(document.f1.qclassicorange.value) +
    parseFloat(document.f1.qclassicblue.value) +
    parseFloat(document.f1.qclassicgreen.value) +
    parseFloat(document.f1.qclassicwhite.value) +
    parseFloat(document.f1.qclassicpurple.value) +
    parseFloat(document.f1.qclassicsilver.value) +
    parseFloat(document.f1.qclassicneon.value) +
    parseFloat(document.f1.qclassicexplorer.value);


    }
    </script>

  10. #10
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    i problemi possibili sono
    1 non esistono i campi di testo, ovvero non esiste <input type="text" name="qclassicblack"/>
    2 in uno dei campi non scrivi un numero valido
    parseFloat riesce a capire bene 123456.7, non bene 123.456,7, per niente valori con caratteri

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.