lundi 11 juillet 2016

If value is x then display y

Hi I have a pretty straight forward problem, and I just do not seem to find the right answer to it.

I have a function that should display 7 different numbers, depending on which radio buttons (t, and c) are selected. This would be okay, if 4 of the radio buttons belonging to "t" weren't meant to display other results than their mathematical ones.

here is what I have so far:

<form onsubmit="return false" onclick="
f1.value=Math.round(((parseFloat(t.value) + (parseFloat(240)/parseFloat(c.value))   ))*100)/100;
f2.value=Math.round(((parseFloat(t.value) + (parseFloat(525)/parseFloat(c.value))   ))*100)/100;
f3.value=Math.round(((parseFloat(t.value) + (parseFloat(570)/parseFloat(c.value))    ))*100)/100;
f4.value=Math.round(((parseFloat(t.value)  + parseFloat(390)/parseFloat(c.value)   ))*100)/100;
f5.value=Math.round(((parseFloat(t.value)  + (parseFloat(435)/parseFloat(c.value))   ))*100)/100;
f6.value=Math.round(((parseFloat(t.value)  + (parseFloat(360)/parseFloat(c.value))   ))*100)/100;
f7.value=Math.round(((parseFloat(t.value)  + (parseFloat(555)/parseFloat(c.value))  ))*100)/100; ">


<table style="float: left; margin-right: 5px; background:transparent">
<tr><td colspan="2" style="text-align: center; font-weight:bold;"><h2>t</h2></td></tr>
<tr><td  style="text-align: center;" width="50%"> <input name="t" type="radio" value="9.58333" checked="true"/>t1</td><td  style="text-align: left; padding-left:20px" width="50%"><input name="t" type="radio" value="7.50" />t1-2</td></tr>
<tr><td  style="text-align: center;" width="50%"> <input name="t" type="radio" value="13.33" />t2</td><td  style="text-align: left; padding-left:20px" width="50%"> <input name="t" type="radio" value="15" />t2-2</td>
</tr>
<tr><td  style="text-align: center;" width="50%"><input name="t" type="radio" value="14.167" />t3</td><td style="text-align: left; padding-left:20px" width="50%"> <input name="t" type="radio" value="17.00" />t3-2</td></tr>
<tr><td  style="text-align: center;" width="50%"><input name="t" type="radio" value="32.5" />t4</td><td style="text-align: left; padding-left:20px" width="50%"> <input name="t" type="radio" value="21.67" />t4-2</td></tr><tr><td  style="text-align: center;" width="50%"></td><td style="text-align: left; padding-left:20px"> <input name="t" type="radio" value="32.5" />t5-2</td></tr>
</table>

<table style="float: left; margin-right: 5px; background:transparent">
<tr><td colspan="1" style="text-align:center"><h2>c</h2></td></tr>
<tr><td style="text-align: center;"><input name="c" type="radio" value="10" />10</td></tr>
<tr><td style="text-align: center;"><input name="c" type="radio" value="24" />20</td></tr>
<tr><td style="text-align: center;"><input name="c" type="radio" value="36" checked="true"  />30</td></tr>
<tr><td style="text-align: center;"></br></td></tr>
<tr><td style="text-align: center;"></br></td></tr>
</table>

<table style="clear: both;">
<tbody><tr><td></td></tr></tbody></table>

<script> 

</script>


f1 <input name="f1" type="output" readonly style="text-align:center;" placeholder="16.67" ></br>
f2 <input name="f2" type="output" readonly style="text-align:center;" placeholder="24.58"/></br>
f3 <input name="f3" type="output" readonly style="text-align:center;" placeholder="25.83"/></br>
f4 <input name="f4" type="output" readonly style="text-align:center;" placeholder="20.83"/></br>
f5 <input name="f5" type="output" readonly style="text-align:center;" placeholder="22.08"/></br>
f6 <input name="f6" type="output" readonly style="text-align:center;" placeholder="15.00"/></br>
f7 <input name="f7" type="output" readonly style="text-align:center;" placeholder="25.42"/></form>

the t's with the "-2" at the end work fine, i.e. I'd like to change the other ones.

E.g. if f3= 30 (which happens if t4 and 36 are selected) I'd like to add 3.34 to the sum.

By now I've tried to add a few things between the script tags like

<script> if(!(f3==30)){return !(value == 33.5);}</script>

but it seems I'm doing it wrong.

I'd really appreaciate some input.

Thanks.

Aucun commentaire:

Enregistrer un commentaire