maj automatique d'adition d'input
bonjour,
J'ai un problème, j'aimerais que mes deux input resultat1 et resultat2 se mettent a jour automatique lorsque l'input chps3, prixoption et resultat sont remplient et que la maj se fasse meme si l'un des 3 input n'est pas remplis.
Est-ce possible et si oui comment faire, je n'y arrive pas
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
<script language="javascript">
function Somme() {
A=document.addit.case1.value;
B=document.addit.case2.value;
C=document.addit.case3.value;
D=document.addit.resultat.value
E=document.addit.resultat1.value
document.addit.resultat.value=Number(A)+Number(B)+Number(C);
document.addit.resultat1.value = Number(D) + parseFloat(document.addit.chps3.value) + parseFloat(document.addit.prixoption.value);
document.addit.resultat2.value = Number(E)*(1+6/100);
}
function UpdateCost() {
var sum = 0;
var gn, elem;
for (i=0; i<5; i++) {
gn = 'option'+i;
elem = document.getElementById(gn);
if (elem.checked == true) { sum += Number(elem.value); }
}
document.addit.prixoption.value = sum.toFixed(2);
}
function sum_elements()
{
for(var i = 1; i<=3; i++)
{
var element = document.getElementById('chps'+i);
}
}
function calculchps3()
{
var chps3= document.getElementById("addit").elements["nbre3"].value * document.getElementById("addit").elements["prix3"].value*25;
document.getElementById("addit").elements["chps3"].value=chps3;
sum_elements();
}
</script> |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
<form method="post" name="addit" id="addit">
<tr>
<td width="400" align="right">longueur (mm)
<input name="nbre3" type="text" size="4" onBlur="calculchps3()" value=""> X </td>
<td align="right">hauteur (mm) = <input name="prix3" type="text" size="4" onBlur="calculchps3()" value=""> = </td>
<td width="190" align="center"> <input id="chps3" name="chps3" type="text" size="8" size="8" value=""></td>
</tr>
<p>
<input type="checkbox" id='option0' value="9.99" onClick="UpdateCost()">Option 1 ( 9.99)<br>
<input type="checkbox" id='option1' value="19.99" onClick="UpdateCost()">Option 2 (19.99)<br>
<input type="checkbox" id='option2' value="27.50" onBlur="UpdateCost()">Option 3 (27.50)<br>
<input type="checkbox" id='option3' value="45.65" onClick="UpdateCost()">Option 4 (45.65)<br>
<input type="checkbox" id='option4' value="87.20" onClick="UpdateCost()">Option 5 (87.20)</p>
<p><br>
Total Option :
<input type="text" name="prixoption" size="7"><br>
</p>
<p><br>
<input type="text" name="case1" onKeyUp="Somme()" size=7>
<input type="text" name="case2" onKeyUp="Somme()" size=7>
<input type="text" name="case3" onKeyUp="Somme()" size=7><br>
<input type="text" name="resultat" size=7><br>
</p>
<p><br>
Total HTVA :
<input type="text" name="resultat1" size=7>
</p>
<p>Total TTC :
<input type="text" name="resultat2" size="7">
</p>
</form> |