Código HTML:
Ver originalBj
<input type="radio" name="box" value="Bj" checked />Mer
<input type="radio" name="box" value="Mer" />Sod
<input type="radio" name="box" value="Sod" />Inc
<input type="radio" name="box" value="Inc" />
<br /> <input type="text" name="watt" />w
<br /> Res:
<input type="text" name="res" value="0" />
Código Javascript
:
Ver originalvar vals = {Bj:2.5,Mer:3.2,Sod:2.5,Inc:8}
var form = document.calc
function calc(){
var i = 0, obj
while(obj = form.box[i++]) if(obj.checked) form.res.value = +form.watt.value / vals[obj.value]
}
var i=0, obj;
while(obj = form.box[i++]) obj.onclick = calc //calcular al clickear boxs
form.watt.onkeyup = calc //calcular al escribir watt