problema disattivazione radio in JS
Ciao a tutti io ho questa tabella:
http://fatturaonline.altervista.org/222.png
che aggiunge righe dinamicamente con questo script:
Codice:
<script language="JavaScript" type="text/javascript">
<!--
var num=2;
var size=15;
function accoda(){
if (num ==10)
size=22;
else if(num==99)
size=27;
if(document.createElement && document.getElementById && document.getElementsByTagName) {
var a="a"+num;
var b="b"+num;
var c="c"+num;
var d="d"+num;
var azionea="des(\"a\","+num+");";
var azioneb="des(\"b\","+num+");";
var azionec="des(\"c\","+num+");";
var azioned="des(\"d\","+num+");";
//alert(a);alert(b);alert(c);alert(d);
// crea elementi
var oTr=document.createElement("TR"); //elemento tr
var Tdprimo=document.createElement("TD"); // indice
var Tdsecondo=document.createElement("TD"); //data
var Tdterzo=document.createElement("TD"); //descrizione
var Tdquarto=document.createElement("TD"); //cassa dare
var Tdquinto=document.createElement("TD"); //cassa avere
var Tdsesto=document.createElement("TD"); //banca dare
var Tdsettimo=document.createElement("TD"); //banca avere
var Tdottavo=document.createElement("TD"); //importo
var primo=document.createElement("INPUT"); // indice
var secondo=document.createElement("INPUT"); //data giorno
var slash1=document.createTextNode(" / "); // slash 1
var terzo=document.createElement("INPUT"); //data mese
var slash2=document.createTextNode(" / "); // slash 2
var quarto=document.createElement("INPUT"); //data anno
var quinto=document.createElement("INPUT"); //descrizione
var sesto=document.createElement("INPUT"); //cassa dare
var settimo=document.createElement("INPUT"); //cassa avere
var ottavo=document.createElement("INPUT"); //banca dare
var nono=document.createElement("INPUT"); //banca avere
var decimo=document.createElement("INPUT"); //importo
// setta attributi
primo.setAttribute("type","text"); // indice
primo.setAttribute("name","indice[]"); // indice
primo.setAttribute("value",num); // indice
primo.setAttribute("size","1"); // indice
primo.setAttribute("style","width:"+size+";"); // indice
primo.setAttribute("readonly","readonly"); // indice
secondo.setAttribute("type","text"); // data giorno
secondo.setAttribute("name","giorno[]"); // data giorno
secondo.setAttribute("value","gg"); // data giorno
secondo.setAttribute("size","2"); // data giorno
secondo.setAttribute("style","width:30px"); // data giorno
secondo.setAttribute("maxlength","2"); // data giorno
terzo.setAttribute("type","text"); // data mese
terzo.setAttribute("name","mese[]"); // data mese
terzo.setAttribute("value","mm"); // data mese
terzo.setAttribute("size","2"); // data mese
terzo.setAttribute("style","width:30px"); // data mese
terzo.setAttribute("maxlength","2"); // data mese
quarto.setAttribute("type","text"); // data anno
quarto.setAttribute("name","anno[]"); // data anno
quarto.setAttribute("value","aaaa"); // data anno
quarto.setAttribute("size","4"); // data anno
quarto.setAttribute("style","width:40px"); // data anno
quarto.setAttribute("maxlength","4"); // data anno
quinto.setAttribute("type","text"); // descrizione
quinto.setAttribute("name","descrizione[]"); // descrizione
quinto.setAttribute("size","30"); // descrizione
quinto.setAttribute("maxlength","40"); // descrizione
sesto.setAttribute("type","radio"); // cassa dare
sesto.setAttribute("name","darecassa[]"); // cassa dare
sesto.setAttribute("value","cd"); // cassa dare
sesto.setAttribute("id",a); // cassa dare
sesto.setAttribute("onclick",azionea); // cassa dare
settimo.setAttribute("type","radio"); // cassa avere
settimo.setAttribute("name","averecassa[]"); // cassa avere
settimo.setAttribute("value","cs"); // cassa avere
settimo.setAttribute("id",b); // cassa avere
settimo.setAttribute("onclick",azioneb); // cassa avere
ottavo.setAttribute("type","radio"); // banca dare
ottavo.setAttribute("name","darebanca[]"); // banca dare
ottavo.setAttribute("value","bd"); // banca dare
ottavo.setAttribute("id",c); // banca dare
ottavo.setAttribute("onclick",azionec); // banca dare
nono.setAttribute("type","radio"); // banca avere
nono.setAttribute("name","averebanca[]"); // banca avere
nono.setAttribute("value","bc"); // banca avere
nono.setAttribute("id",d); // banca avere
nono.setAttribute("onclick",azioned); // banca avere
decimo.setAttribute("type","text"); // importo
decimo.setAttribute("name","importo[]"); // importo
decimo.setAttribute("size","8"); // importo
decimo.setAttribute("maxlength","8"); // importo
// appendi al relativo padre
Tdprimo.appendChild(primo);
Tdsecondo.appendChild(secondo);
Tdsecondo.appendChild(slash1);
Tdsecondo.appendChild(terzo);
Tdsecondo.appendChild(slash2);
Tdsecondo.appendChild(quarto);
Tdterzo.appendChild(quinto);
Tdquarto.appendChild(sesto);
Tdquinto.appendChild(settimo);
Tdsesto.appendChild(ottavo);
Tdsettimo.appendChild(nono);
Tdottavo.appendChild(decimo);
//elemento td
oTr.appendChild(Tdprimo);
oTr.appendChild(Tdsecondo);
oTr.appendChild(Tdterzo);
oTr.appendChild(Tdquarto);
oTr.appendChild(Tdquinto);
oTr.appendChild(Tdsesto);
oTr.appendChild(Tdsettimo);
oTr.appendChild(Tdottavo);
//elemento tr
document.getElementById('tabella').getElementsByTagName('TBODY')[0].appendChild(oTr);
// incrementa variabile globale
num++
}
}
function rimuovi(){
if(document.removeChild && document.getElementById && document.getElementsByTagName) {
// se non e' la prima riga
if(num>2){
// riferimento al tbody
var tb=document.getElementById('tabella').getElementsByTagName('TBODY')[0];
// riferimento all' ultimo TR
var lastTr=tb.getElementsByTagName('TR')[(tb.getElementsByTagName('TR').length)-1]
// rimuovi
tb.removeChild(lastTr);
// decrementa variabile globale
num--
}
}
}
//-->
</script>
la funzione dei radio e che può esserne selezionato solo uno per riga con questa funzione javascript:
Codice:
function des(cosa,n){
alert(cosa);
alert(n);
var na= "a"+n;
var nb= "b"+n;
var nc= "c"+n;
var nd= "d"+n;
var elementa="document.getElementById(\""+na+"\")";
var elementb="document.getElementById(\""+nb+"\")";
var elementc="document.getElementById(\""+nc+"\")";
var elementd="document.getElementById(\""+nd+"\")";
alert(nb);
alert(elementb);
if (cosa=="a"){
elementb.checked = false; // abilito tutto fuorchè A
elementc.checked = false;
elementd.checked = false;
}
else if (cosa=="b"){
elementa.checked= false; // abilito tutto fuorchè B
elementc.checked= false;
elementd.checked= false;
}
else if (cosa=="c"){
elementa.checked= false; // abilito tutto fuorchè C
elementb.checked= false;
elementd.checked= false;
}
else{
elementa.checked= false; //abilito tutto fuorchè D
elementb.checked= false;
elementc.checked= false;
}
}
Il problema è che non funziona bene si possono selezionare solo un radio per colonna.