I want to crete a form for my invoices. I'm a very newbie in JS, I know just som few things. I have two problem:
1. I want a functions for calculate a cost with and without tax. I 'm creating this:
Code: Select all
<script type="text/javascript">
// (x) is a number of the php generated row (see the code)
function FwoTax(x) {
woTax+x+.value = eval(quoty+x+.value) * eval(cost+x+.value);
}
function FwTax(x) {
wTax+x+.value = eval(woTax+x+.value)*(eval(tax+x+.value)/100+1);
}
</script>2. I'm try the js function without (x) with fixed index woTax1.value (for the 1st row) it worked but not with the Cost with Tax, this one was not be calculated, while I don't change the Tax list.
Code: Select all
<form id="form1" name="form1" method="post" action="">
<?php
if (!isset ($defRepeat)) {
$defRepeat = 1;
}
for ($repeat = 1; $repeat <= $defRepeat; $repeat++) {
?>
<p>
<label>Qty:
<input name="quoty<? echo $repeat;?>" type="text" id="quoty<? echo $repeat;?>" onchange="FwoTax(<? echo $repeat;?>);" />
</label>
<label>Cost/Qty without Tax:
<input type="text" name="cost<? echo $repeat;?>" id="cost<? echo $repeat;?>" onchange="FwoTax(<? echo $repeat;?>);" />
</label>
<label>Tax %:
<select name="tax<? echo $repeat;?>" id="tax<? echo $repeat;?>" onchange="FwTax();">
<option value="19">19</option>
<option value="10">10</option>
<option value="0">0</option>
</select>
</label>
<label>Cost without Tax:
<input name="woTax<? echo $repeat;?>" type="text" id="woTax<? echo $repeat;?>" onchange="FwTax();"/>
</label>
<label>Cost with Tax:
<input type="text" name="wTax<? echo $repeat;?>" id="wTax<? echo $repeat;?>" disabled/>
</label>
<br />
<?php
if ($repeat == $defRepeat) {
echo ("<a href=\"?defRepeat=".($defRepeat + 1)."\">Add Row</a>");
if ($defRepeat > 1) {
echo ("<br /><a href=\"?defRepeat=".($defRepeat - 1)."\">Remove Row</a>");
}
}
?>
</p>
<?php } ?>
</form>
Thank you very much for any help.
G.