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

    Test con risposta multipla

    Devo costruire un questionario, per quanto riguarde le risposte con i radio button sono ok.
    Ho un problema con una domanda che prevede 8 scelte su 20.
    Come posso costruire un controllo per far si che non si possa fleggare più di 8 caselle e che se ne vengono selezionate di meno mi attivi un allert?

    La domanda è tipo:

    Scegli 8 città dove ti piacerebbe trascorre u week-end:
    O Milano O Palermo
    O Roma O Messina
    O Verona O Lecce
    O Madrid O Parigi
    O Londra O Berlino
    O Mosca O Lisbona
    O Singapore O Atene

  2. #2
    Anziche usare 20 radio, usi 20 checked no??
    Quando clicchi per confermare la risposta richiami una funzione javascript che controlla quanti ne hai fleggati...

    codice:
    <input type="checkbox" id="uno">UNO
    <input type="checkbox" id="due">DUE
    <input type="checkbox" id="tre">TRE
    <input type="checkbox" id="quattro">QUATTRO
    <input type="checkbox" id="cinque">CINQUE
    <input type="checkbox" id="sei">SEI
    <input type="checkbox" id="sette">SETTE
    <input type="checkbox" id="otto">OTTO
    <input type="checkbox" id="nove">NOVE
    <input type="button" value="Controllo" onClick="Controllo()">

    Devi solo fare la funzione "Controllo()" ora

  3. #3
    Mi aiuteresti con la funzione controllo?
    Ho già impostato i chek, come dovrei strutturare la funzione?

  4. #4
    Chi mi aiuta a scrivere la funzione per testare se i checkbox sono flaggati?

    Questa è la funzione che viene richiamata quando si clikka su un check.

    function Engine2(question, answer) {
    check[question]=answer;
    }

    Questa è la struttura dei check.

    <tr>
    <td width="120"><span class="Stile6">
    <label>
    <input type="checkbox" name="d1" id="d1" value="S" onClick="Engine2(1, this.value)"/>
    </label>
    Balanced

    <input type="checkbox" name="d2" id="d2" value="S"/>
    Cautious

    <input type="checkbox" name="d3" id="d3" value="S"/>
    Cold

    <input type="checkbox" name="d4" id="d4" value="S"/>
    Meticulous

    </span></td>
    <td width="120"><span class="Stile6">
    <input type="checkbox" name="d5" id="d5" value="S"/>
    Realistic

    <input type="checkbox" name="d6" id="d6" value="S"/>
    Concrete

    <input type="checkbox" name="d7" id="d7" value="S"/>
    Committed

    <input type="checkbox" name="d8" id="d8" value="S"/>
    Obstinate

    </span></td>
    <td width="120"><span class="Stile6">
    <input type="checkbox" name="d9" id="d9" value="S"/>
    Efficient

    <input type="checkbox" name="d10" id="d10" value="S"/>
    Practical

    <input type="checkbox" name="d12" id="d12" value="S"/>
    Precise

    <input type="checkbox" name="d11" id="d11" value="S"/>
    Clean

    </span></td>
    <td width="120"><input type="checkbox" name="d13" id="d13" value="S"/>
    Careful

    <input type="checkbox" name="d14" id="d14" value="S"/>
    Organised

    <input type="checkbox" name="d16" id="d16" value="S"/>
    Determined

    <input type="checkbox" name="d15" id="d15" value="S"/>
    Secure</td>
    <td width="120"><span class="Stile6">
    <input type="checkbox" name="d17" id="d17" value="D"/>
    Observer

    <input type="checkbox" name="d18" id="d18" value="D"/>
    Original

    <input type="checkbox" name="d19" id="d19" value="D"/>
    Enthusiastic

    <input type="checkbox" name="d20" id="d20" value="D"/>
    Dynamic

    </span></td>
    <td width="120"><span class="Stile6">
    <input type="checkbox" name="d21" id="d21" value="D"/>
    Brave

    <input type="checkbox" name="d22" id="d22" value="D"/>
    Acute

    <input type="checkbox" name="d24" id="d24" value="D"/>
    Selfdemanding

    <input type="checkbox" name="d23" id="d23" value="D"/>
    Corageous

    </span></td>
    <td width="120"><span class="Stile6">
    <input type="checkbox" name="d25" id="d25" value="D"/>
    </span>Curious

    <span class="Stile6">
    <input type="checkbox" name="d26" id="d26" value="D"/>
    </span>Elastic

    <span class="Stile6">
    <input type="checkbox" name="d27" id="d27" value="D"/>
    </span>Fast

    <span class="Stile6">
    <input type="checkbox" name="d28" id="d28" value="D"/>
    </span>Independent</td>
    <td width="120"><span class="Stile4"><span class="Stile6">
    <input type="checkbox" name="d29" id="d29" value="D"/>
    </span>Lively

    <span class="Stile6">
    <input type="checkbox" name="d30" id="d30" value="D"/>
    </span>Witful

    <span class="Stile6">
    <input type="checkbox" name="d31" id="d31" value="D"/>
    </span>Innovator

    <span class="Stile6">
    <input type="checkbox" name="d32" id="d32" value="D"/>
    </span>Passionate</span></td>
    </tr>

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2000
    Messaggi
    1,309
    così va bene?? prova.
    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <
    title>Documento senza titolo</title>
    <
    script>
        function 
    controlla() {
            var 
    strChech=document.frmTest.d1;
            var 
    strControllo 0;
            
    //alert(strChech[0].checked);
            
            
    for (var i=0i<=strChech.length-1;i++) {
                if (
    strChech[i].checked==true) {
                    
    //alert(strChech[i].id);
                    
    strControllo +=1;
                }
            }
            
            if (
    strControllo>8) {
                
    alert("errore: non puoi selezionare più di otto valori");
            } else {
                
    alert("controllo ok");
            }
            
        }
    </script>
    </head>

    <body>

    <form name="frmTest">
    <table>
        
    <tr>
    <td width="120"><span class="Stile6">
    <label>
    <input type="checkbox" name="d1" id="d1" value="S"/>
    </label>
    Balanced 

    <input type="checkbox" name="d1" id="d2" value="S"/>
    Cautious

    <input type="checkbox" name="d1" id="d3" value="S"/>
    Cold

    <input type="checkbox" name="d1" id="d4" value="S"/>
    Meticulous
     
    </span></td>
    <td width="120"><span class="Stile6">
    <input type="checkbox" name="d1" id="d5" value="S"/>
    Realistic

    <input type="checkbox" name="d1" id="d6" value="S"/>
    Concrete

    <input type="checkbox" name="d1" id="d7" value="S"/>
    Committed

    <input type="checkbox" name="d1" id="d8" value="S"/>
    Obstinate
     
    </span></td>
    <td width="120"><span class="Stile6">
    <input name="d1" type="checkbox" id="d9" value="S"/>
    Efficient

    <input type="checkbox" name="d1" id="d10" value="S"/>
    Practical

    <input type="checkbox" name="d1" id="d12" value="S"/>
    Precise

    <input type="checkbox" name="d1" id="d11" value="S"/>
    Clean
     
    </span></td>
    <td width="120"><input type="checkbox" name="d1" id="d13" value="S"/>
    Careful

    <input type="checkbox" name="d1" id="d14" value="S"/>
    Organised

    <input type="checkbox" name="d1" id="d16" value="S"/>
    Determined

    <input type="checkbox" name="d1" id="d15" value="S"/>
    Secure</td>
    <td width="120"><span class="Stile6">
    <input type="checkbox" name="d1" id="d17" value="D"/>
    Observer

    <input type="checkbox" name="d1" id="d18" value="D"/>
    Original

    <input type="checkbox" name="d1" id="d19" value="D"/>
    Enthusiastic

    <input type="checkbox" name="d1" id="d20" value="D"/>
    Dynamic
     
    </span></td>
    <td width="120"><span class="Stile6">
    <input type="checkbox" name="d1" id="d21" value="D"/>
    Brave

    <input type="checkbox" name="d1" id="d22" value="D"/>
    Acute

    <input type="checkbox" name="d1" id="d24" value="D"/>
    Selfdemanding

    <input type="checkbox" name="d23" id="d23" value="D"/>
    Corageous
     
    </span></td>
    <td width="120"><span class="Stile6">
    <input type="checkbox" name="d1" id="d25" value="D"/>
    </span>Curious

    <span class="Stile6">
    <input type="checkbox" name="d1" id="d26" value="D"/>
    </span>Elastic

    <span class="Stile6">
    <input type="checkbox" name="d1" id="d27" value="D"/>
    </span>Fast

    <span class="Stile6">
    <input type="checkbox" name="d1" id="d28" value="D"/>
    </span>Independent</td>
    <td width="120"><span class="Stile4"><span class="Stile6">
    <input type="checkbox" name="d1" id="d29" value="D"/>
    </span>Lively

    <span class="Stile6">
    <input type="checkbox" name="d1" id="d30" value="D"/>
    </span>Witful

    <span class="Stile6">
    <input type="checkbox" name="d1" id="d31" value="D"/>
    </span>Innovator

    <span class="Stile6">
    <input type="checkbox" name="d1" id="d32" value="D"/>
    </span>Passionate</span></td>
    </tr>
    </table>


    <input type="button" value="invia" onclick="controlla();" /></p>
    </form>
    </body>
    </html> 
    Ciao By Peter_Pan...

  6. #6
    La tua paginetta funziona ma se la inserisco nella mia non và.

    Questa è la funzione che calcola il punteggio. Viene richiamata dalla tua funzione controlla() quando il chek è andato a buon fine.

    Dove sbaglio?

    var ans = new Array;
    var done = new Array;
    var yourAns = new Array;
    var strChech=document.frmTest.d1;
    var explainAnswer = new Array;
    var score = 0;

    explainAnswer[1]="PRESSURE: Resistant to creativity: purgatory of creativity.\n Their season is winter. \n";
    explainAnswer[2]="PRESSURE: Creative for function: they would never do it i they knew it is absolutely necessary. \n Their season is autumn.\n";
    explainAnswer[3]="PRESSURE: Creative for necessity: continuous challenge, self-motivating, look for them inside the organization.\n Their season is spring.\n";
    explainAnswer[4]="PRESSURE: Creative for pleasure: they enjoy in creating, they must be motivated.\n Their season is summer.\n";

    function Score()
    {
    var answerText = "What Creative are you?\n------------------------------------\n";
    //now score the user
    s=0;
    d=0;
    for(i=1;i<=32;i++)
    {ck="d"+i;
    if (strChech[i].checked==true)
    {
    if(strChech[i]=="S")
    {s++;}
    if(strChech[i]=="D")
    {d++;}
    }
    }

    for(i=1;i<=49;i++)
    {
    if(yourAns[i]=="S")
    {s++;}
    if(yourAns[i]=="D")
    {d++;}
    }
    score=s+d;
    if(score>=10 && score <=19){
    answerText=answerText+explainAnswer[1];
    }
    if(score>=20 && score <=29){
    answerText=answerText+explainAnswer[2];
    }
    if(score>=30 && score <=39){
    answerText=answerText+explainAnswer[3];
    }
    if(score>=40 && score <=49){
    answerText=answerText+explainAnswer[4];
    }
    answerText=answerText+"\nRIGHT : "+d+"\nLEFT: "+s;

    alert(answerText);
    }

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 © 2026 vBulletin Solutions, Inc. All rights reserved.