:master: prova a vedere se funziona
codice:
<!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>
<title>Pagina senza titolo</title>
<script language="javascript" type="text/javascript">
// <!CDATA[
//dalla libreria prototype-1.4.0.js
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
function valore_radiobutton_selezionato(rb)
{
if(rb == undefined) return null;
var n, i, v, m, vv;
n = rb.length;
if(n != undefined)
{
v = -1;
for (i = 0; i < n; i++)
{
if (rb[i].checked)
{
v = i;
vv = rb[i].value;
break;
}
}
if (v >= 0)
return vv;
else
return null;
}
else
{
if(rb.checked)
return rb.value;
else
return null;
}
}
window.onload = function()
{
$("Checkbox1").onclick = aggiorna;
for(var i = 1; i <= 3; i++) $("r1_" + i).onclick = aggiorna;
for(var i = 1; i <= 2; i++) $("r2_" + i).onclick = aggiorna;
}
function aggiorna()
{
if(valore_radiobutton_selezionato($("form1").r1) == null) return;
if(valore_radiobutton_selezionato($("form1").r2) == null) return;
var r1 = 0;
var r2 = 0;
if($("r2_1").checked)
{
if($("Checkbox1").checked)
{
r1 = ( parseInt(valore_radiobutton_selezionato($("form1").r1),10) + parseInt($("Checkbox1").value, 10) )/10;
}
else
{
r1 = ( parseInt(valore_radiobutton_selezionato($("form1").r1),10) )/10;
}
$('Text1').value = r1;
}
else
{
if($("Checkbox1").checked)
{
r2 = ( parseInt(valore_radiobutton_selezionato($("form1").r1),10) + parseInt($("Checkbox1").value, 10) );
}
else
{
r2 = ( parseInt(valore_radiobutton_selezionato($("form1").r1),10) );
}
$('Text2').value = r2;
}
}
// ]]>
</script>
</head>
<body>
<form id="form1" action="?">
<input id="Checkbox1" type="checkbox" value="5" />
<input id="r1_1" type="radio" name="r1" value="10" />
<input id="r1_2" type="radio" name="r1" value="20" />
<input id="r1_3" type="radio" name="r1" value="30" />
<input id="r2_1" type="radio" name="r2" value="A" />
<input id="r2_2" type="radio" name="r2" value="B" />
<hr />
<input id="Text1" type="text" />
<input id="Text2" type="text" />
</form>
</body>
</html>