Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Funzione script

  1. #1
    Utente di HTML.it
    Registrato dal
    May 2006
    Messaggi
    442

    Funzione script

    la seguennte funzione a seconda di quali checkbox sono checked dovvrebbe mostrarmi il totale
    Ho provato a farla in qiuesto modo

    function Host()
    {
    var win=document.hosting.checked;
    var lin=document.hosting2.checked;
    var winlin=document.hosting3.checked;
    var tot;
    if (win && lin && winlin)
    {
    tot=win+lin+winlin;
    return tot=105;
    }

    else if(win && lin)
    {


    tot=win+lin;
    return tot=60;
    }

    else if(win && winlin)
    {

    $tot=win+winlin;
    return tot=75;
    }
    else if(lin && winlin)
    {

    tot=lin+winlin;
    return tot=75;
    }

    else if(win)
    {

    tot=win;
    return tot=30;
    }


    else if(lin)
    {

    tot=win;
    return tot=30;
    }



    else if(winlin)
    {

    tot=winlin;
    return tot=45;
    }

    else
    {
    tot=0;
    return tot=0;
    }
    document.write(tot);
    }


    grazie se qualcuno mi può aiutare

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2006
    Messaggi
    121
    Per me, se ho ben capito quello che vuoi fare,hai fatto proprio un errore di base e ti sei impelagato in una quantità eccessiva di condizioni.
    Innanzitutto attribuisci alle 3 diverse checkbox un value con il loro valore per esempio:

    <input type="checkbox" name="hosting" id="hosting" value="30" />


    poi la funzione la strutturi in questa maniera:

    function Host()
    {
    var win=document.getElementById('hosting');
    var lin=document.getElementById('hosting2');
    var winlin=document.getElementById('hosting3');
    var tot =0 ;

    if (win.checked==true)
    tot+=win.value;
    if (lin.checked==true)
    tot+=lin.value;
    if (winlin.checked==true)
    tot+=winlin.value;

    return tot;
    }

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2006
    Messaggi
    442

    Rispoasta

    servizi.js

    function Host()
    {
    var win=document.getElementById('win');
    var lin=document.getElementById('lin');
    var winlin=document.getElementById('winlin');
    var tot =0 ;

    if (win.checked==true)
    tot+=win.value;
    if (lin.checked==true)
    tot+=lin.value;
    if (winlin.checked==true)
    tot+=winlin.value;

    return tot;
    }


    servvizi.php
    <script src=\"jvs/servizi.js\" type=\"text/javascript\"></script>
    echo "<center><table><tr>
    <td><input type=\"checkbox\" name=\"win\" id=\"win\" value=\"30\" />Win</td><td>30 €</td></tr>
    <tr><td><input type=\"checkbox\" name=\"lin\" id=\"lin\" value=\"30\" />Win</td><td>30 €</td></tr>
    <tr><td><input type=\"checkbox\" name=\"winlin\" id=\"winlin\" value=\"45\" />Win</td><td>45 €</td></tr>
    <tr><td><input name=ciao type=button value=memorizza onclick=javascript:Host();></td></tr>
    </table>
    </center>

    facendo in questo modo non funziona ugualmente e non so perchè
    se mi puoi aiutare...
    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.