<?php
$items=$_REQUEST['items']; // se pari lexojme sa elemente do te kete buxheti ne variablin $items
?>
<html>
<head>
<title>Buxheti</title>
<script language="JavaScript">
function sumline(i)
{
var price,qty,itemvalue;
price=document.getElementById("Item_Price_"+i);
qty=document.getElementById("Item_Qty_"+i);
itemvalue=document.getElementById("Item_Value_"+i);
itemvalue.value=parseFloat(price.value)*parseFloat(qty.value);
//recalculate totals
totals();
}
function totals()
{
var n,i,s;
s=0; // inicializojme shumen me 0
n=<?php echo $items; ?>;
for(i=1;i<=n;i++)
{
itemvalue=document.getElementById("Item_Value_"+i);
s=s+parseFloat(itemvalue.value); // shtojme vleren e rreshtit tek totali
}
buxheti.total.value=s;
}
</script>
</head>
<body>
<form name="buxheti" action="#" method="post">
<table bgcolor="#99CCFF" >
<tr>
<th>No</th>
<th>Item</th>
<th>Price</th>
<th>Quantity</th>
<th>Value</th>
</tr>
<?php
for($i=1;$i<=$items;$i++)
{
?>
<tr>
<td><input value="<?php echo $i ?>" size="2" type="text" name="Item_<?php echo $i; ?>"></td>
<td><input size="50" type="text" name="Item_Name_<?php echo $i; ?>" id="Item_Name_<?php echo $i; ?>" ></td>
<td ><input size="5" value="0.0" type="text" name="Item_Price_<?php echo $i; ?>" id="Item_Price_<?php echo $i; ?>"onChange="sumline(<?php echo $i; ?>);" ></td>
<td><input size="5" value="0.0" type="text" name="Item_Qty_<?php echo $i; ?>" id="Item_Qty_<?php echo $i; ?>"onChange="sumline(<?php echo $i; ?>);"></td>
<td ><input size="5" value="0.0" type="text" name="Item_Value_<?php echo $i; ?>" id="Item_Value_<?php echo $i; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td>---</td>
<td>TOTAL</td>
<td>---</th>
<td>---</td>
<td><input size="5" type="text" name="total"></td>
</tr>
</table>
</form>
</body>
</html>