Valore checkbox selezionato sempre `undefined`
Ciao a tutti.
non riesco a far valorizzare correttamente il valore del checkbox selezionato in questa pagina html, restituisce sempre `undefined`.
Cosa sbaglio?
Grazie
codice:<html> <head> <title>Seleziona Mailing List</title> <SCRIPT> <!-- function controllo_check() { var cks = document.forms[0].chkParent; var checked = false; for(var i = 0; i < cks.length; i++) { if(cks[i].checked) { checked = true; break; } } return checked; } function insertf1(f1) { if (!controllo_check()) { //se non seleziono almeno un elemento, avviso e uscita alert("Devi selezionare almeno una Mailing List"); return; } //altrimenti altra azione, per esempio stampa valore checkbox selezionato alert("Valore del checkbox:" + document.myform.chkParent.value); } function testSelections(currSel) { // Inizializza il contatore nSel, nCheckboxes viene // impostato col numero di checkboxes con id=chk presenti nel FORM var n, nSel = 0, nCheckboxes = document.myform.chkParent.length; // Conta i checkboxes con id=chk selezionati for ( n = 0 ; n < nCheckboxes ; n++ ) if (document.myform.chk[n].checked) nSel++; if (nSel > 1) // più di 1 selezione ? { // Resetta la selezione appena effettuata document.myform.chk[currSel].checked = false; // Messaggio da personalizzare, informare l'utente che deve // deselezionare un'opzione prima di effettuare la scelta corrente alert("Non è possibile selezionare più di una Mailing List."); } } // --> </script> </head> <body> <form id="myform" name="myform"> <p class=blub><input type=checkbox id=chk name=chkParent value=4 onclick=testSelections(0);>ANAGNI</p> <p class=blub><input type=checkbox id=chk name=chkParent value=6 onclick=testSelections(1);>APRILIA</p> <p class=blub><input type=checkbox id=chk name=chkParent value=2 onclick=testSelections(2);>CASSINO</p> <p class=blub><input type=checkbox id=chk name=chkParent value=7 onclick=testSelections(3);>FORMIA</p> <p class=blub><input type=checkbox id=chk name=chkParent value=1 onclick=testSelections(4);>FROSINONE</p> <p class=blub><input type=checkbox id=chk name=chkParent value=5 onclick=testSelections(5);>LATINA</p> <p class=blub><input type=checkbox id=chk name=chkParent value=3 onclick=testSelections(8);>SORA</p> <p class=blub><input type=checkbox id=chk name=chkParent value=8 onclick=testSelections(9);>TERRACINA</p> <p class=blub> <a href="javascript:insertf1(document.myform.chkParent.value);"> [img]/images/salva_button.gif[/img]</a></p> </form> </body> </html>

Rispondi quotando
