4
« il: 18 Gen 2014, 20:15:59 »
ciao,
premetto che è un esempio che ho raccolto su internet e una volta capito come farlo funzionare lo personalizzo.
-il tutto mi serve perchè voglio costruire un form per costruire una fattura.-
ho creato un form e nella sezione "OnLoad" ho inserito i seguenti action:
1. Custom code:
<table style="font-family:arial;font-size:12px" width="350px" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr bgcolor="#A00">
<td width="5%" style="padding: 4px;"><font color="#FFF"><b>Antal</b></font>
</td>
<td width="35%" style="padding: 4px;"><font color="#FFF"><b>Produkt</b></font>
</td>
<td colspan="2" width="18%" style="padding: 4px;"><font color="#FFF"><b>Pris/st</b></font>
</td>
<td width="18%" style="padding: 4px;"><font color="#FFF"><b>Summa</b></font>
</td>
</tr>
<tr>
<td>
<input name="quantity" id="ant1" size="5" type="text">
</td>
<td>Original Dalagåvan</td>
<td class="pris1" style="text-align: right; padding-right: 3px;">
<input name="gava" type="text" id="dgorig" size="5" value="440" />
</td>
<td width="10px">kr</td>
<td>
<input name="summa1" id="sum1" size="10" type="text">
</td>
</tr>
<tr>
<td>
<input name="antal2" id="ant2" size="5" type="text">
</td>
<td>Lyx Dalagåvan</td>
<td class="pris2" style="text-align: right; padding-right: 3px;">
<input name="gava" type="text" id="dglyx" size="5" value="550" />
</td>
<td>kr</td>
<td>
<input name="summa2" id="sum2" size="10" type="text">
</td>
</tr>
<tr>
<td>
<input name="antal3" id="ant3" size="5" type="text">
</td>
<td>Lilla Dalagåvan</td>
<td class="pris3" style="text-align: right; padding-right: 3px;">
<input name="gava" type="text" id="dglilla" size="5" value="220" />
</td>
<td>kr</td>
<td>
<input name="summa3" id="sum3" size="10" type="text">
</td>
</tr>
<tr>
<td colspan="4" style=" text-alignpx: right; padding-right: 5px;"><span style="font-weight: bold;">Total summa:</span>
</td>
<td>
<input name="total" id="total" size="10" type="text" />
</td>
</tr>
</tbody>
</table>
<br>
<button id="calculate">Calculate</button>
2. Load JS:
var button = document.getElementById('calculate');
button.onclick = function(){
var ant1 = document.getElementById('ant1').value,
ant2 = document.getElementById('ant2').value,
ant3 = document.getElementById('ant3').value;
var const1 = document.getElementById('dgorig').value,
const2 = document.getElementById('dglyx').value,
const3 = document.getElementById('dglilla').value;
var sum1 = document.getElementById('sum1'),
sum2 = document.getElementById('sum2'),
sum3 = document.getElementById('sum3');
var total = document.getElementById('sum3');
sum1 = sum1.value = ant1 * const1;
sum2 = sum2.value = ant2 * const2;
sum3 = sum3.value = ant3 * const3;
document.getElementById('total').value = sum1 + sum2 + sum3;
};
dovrebbe klikkando calcolare le celle sum1, sum2,sum3 e total