Código Javascript
:
Ver original<html>
<head>
<script type="text/javascript">
function calcular(obj, opc){
if(opc==1)
obj.checked = (document.getElementById("chk_todos").checked==true)?true:false;
var val = (obj.checked == true)? obj.id.split("_")[1] : 0;
obj.value = val;
document.getElementById("text_"+ obj.id.split("_")[1]).value = val;
}
function calcularTodos(){
for(var i = 0 ; i < document.getElementsByName("chk").length; i++)
calcular(document.getElementsByName("chk")[i], 1);
}
</script>
</head>
<body>
<form>
<input name='chk' type='checkbox' id="check_1" onclick="calcular(this,0);" />
Cambia value
Value del checkbox:
<input type="text" id="text_1" />
<input name='chk' type='checkbox' id="check_2" onclick="calcular(this,0);" />
Cambia value
Value del checkbox:
<input type="text" id="text_2" />
<br>
Todos:
<input type='checkbox' id='chk_todos' onclick="calcularTodos();" />
</form>
</body>
</html>