Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2012
    Messaggi
    19

    Riempire TextArea con scelte dal Form e sommare Prezzi

    Ciao a tutti, sono nuova qui, vi spiego il mio problema: ho un form con checkbox, radio, select a cui sono associati dei prodotti con dei prezzi. Quando l'utente li seleziona, vorrei che

    1) i prezzi venissero sommati in una casella di testo che si aggiorna ad ogni scelta
    2) le opzioni che man mano vengono selezionate dai checkbox, dai radio e dai select siano riportate in una textarea che riepiloga il tutto (e che deve essere passata ad un database)
    3) La somma dei prezzi deve poter funzionare con cifre decimali

    Al momento ho fatto questo codice, dove manca la textarea e le cifre decimali:

    Grazie davvero a tutti coloro che avranno la pazienza di suggerirmi come procedere!


    Ecco il codice:

    <html>
    <head>


    <script language="JavaScript">

    function somma(v,s){
    var f=document.WebToLeadForm;
    var realvalue=(f.c.value=="")?0arseFloat(f.c.value);
    if(s) f.c.value=realvalue+parseFloat(v);
    else f.c.value=realvalue-parseFloat(v);
    }

    </script>




    <script type="text/javascript">
    function selectValue(caller)
    {
    document.getElementById("txtRisultato").value = parseFloat(document.getElementById("select1").valu e);
    }
    </script>



    <style type="text/css">
    body {
    width:960px;
    margin:auto;
    margin-top:20px;
    font-family: Arial;
    }
    .divs {
    padding:10px;
    border:1px dashed #333333;
    background: #F3F3F3;
    color:#000;
    width:600px;
    height:20px;
    margin-top:20px;
    }

    .divs p {
    color:#666666;
    }
    </style>



    <title>Spesa</title>

    </head>

    <body>
    <form name="MioForm">

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="12%">Prodotto</td>
    <td width="10%">Tipo</td>
    <td width="78%">Quantità/Prezzo</td>
    </tr>
    <tr>
    <td height="24"></td>
    <td></td>
    <td></td>
    </tr>
    <tr>
    <td height="64">BARILLA</td>
    <td>Penne</td>
    <td><div id="penne_barilla" class="divs">
    <input onChange="document.getElementById('txtarea').inner HTML= document.getElementById('txtarea').value+this.valu e;" type="checkbox" value="1KG " onClick="somma(this.id, this.checked);" id="1.30" name="c1"/>
    1Kg (€ 1,00)

    <input onChange="document.getElementById('txtarea').inner HTML= document.getElementById('txtarea').value+this.valu e;" type="checkbox" value="20" onClick="somma(this.id, this.checked);" id="2" name="c1"/>
    2Kg (€ 2,00)
    <input onChange="document.getElementById('txtarea').inner HTML= document.getElementById('txtarea').value+this.valu e;" type="checkbox" value="3" onClick="somma(this.id, this.checked);" id="3" name="c1"/>
    3Kg (€ 3,00)
    </div>



    </td>
    </tr>
    <tr>
    <td height="64"></td>
    <td>Spaghetti</td>
    <td><div id="penne_barilla" class="divs">
    <input onChange="document.getElementById('txtarea').inner HTML= document.getElementById('txtarea').value+this.valu e;" type="checkbox" value="1KG " onClick="somma(this.id, this.checked);" id="4" name="c1"/>
    1Kg (€ 4,00)

    <input onChange="document.getElementById('txtarea').inner HTML= document.getElementById('txtarea').value+this.valu e;" type="checkbox" value="20" onClick="somma(this.id, this.checked);" id="5" name="c1"/>
    2Kg (€ 5,00)
    <input onChange="document.getElementById('txtarea').inner HTML= document.getElementById('txtarea').value+this.valu e;" type="checkbox" value="3" onClick="somma(this.id, this.checked);" id="6" name="c1"/>
    3Kg (€ 6,00)
    </div></td>
    </tr>


    <tr>
    <td height="64">ANTONIO AMATO</td>
    <td>Linguine</td>
    <td><div id="penne_barillaz" class="divs"> Quantità: <select id="select1" OnChange="javascript: selectValue(this);">
    <option value="0">0</option>
    <option value="2">1Kg (€ 2,00)</option>
    <option value="4">2Kg (€ 4,00)</option>
    <option value="6">3Kg (€ 6,00)</option>
    </select></div>

    <div id="spaghetti_barillaz" class="divs" style="display:none">
    <input onchange="document.getElementById('txtarea').inner HTML= document.getElementById('txtarea').value+this.valu e;" type="checkbox" value="4" onClick="somma(this.value, this.checked);" name="c1"/>
    1Kg (€ 4,00)
    <input type="checkbox" value="5" onClick="somma(this.value, this.checked);" name="c2"/>
    2Kg (€ 5,00)
    <input type="checkbox" value="6" onClick="somma(this.value, this.checked);" name="c3"/>
    3Kg (€ 6,00)

    </div>

    </td>
    </tr>
    <tr>
    <td height="64"></td>
    <td></td>
    <td> <textarea name="riepilogo" id="txtarea"> </textarea></td>
    </tr>
    </table>




    </p>


    </p>


    Totale Spesa: €
    <input id="txtRisultato" type="text" name="c" value="0"/>
    </p>
    </form>
    </body>
    </html>

  2. #2
    Non è necessario usare un tag:
    <script language="JavaScript">
    per ogni funzione, puoi usarne uno solo che conterrà tutto il codice js.

    Ho letto il codice velocemente ma l'innerHTML alla textarea molto probabilmente non funziona perchè usi l'evento onChange associato ad una checkbox, dovresti cercare di gestire tutto con l'onClick.


  3. #3
    Utente di HTML.it
    Registrato dal
    Aug 2012
    Messaggi
    19
    Originariamente inviato da lucavizzi
    Non è necessario usare un tag:
    <script language="JavaScript">
    per ogni funzione, puoi usarne uno solo che conterrà tutto il codice js.

    Ho letto il codice velocemente ma l'innerHTML alla textarea molto probabilmente non funziona perchè usi l'evento onChange associato ad una checkbox, dovresti cercare di gestire tutto con l'onClick.

    Ciao Luca, grazie del suggerimento. Ho ripulito secondo le tue indicazioni. Resto in attesa di altre dritte. Grazie

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.