Thanks that makes sense and it works perfectly as a standalone calculator.
Now....I am getting more complicated now..i need this calculator to work as part of my complete script.
Would you be so kind to try my script?
<html>
<head>
<?php
$referencia= substr(number_format(time() * rand(),0,'',''),0,10); //random number generator
?>
<script type="text/javascript" src="../js/calculator.js"></script>
<script src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script>
$(document).ready(function() {
var id = 0; // usar esto si queremos que la i sea 1, 2, 3 etc
var id = (<?php echo $referencia ;?>);
// Add button functionality
$("table.dynatable button.add").click(function() {
id++;
var master = $(this).parents("table.dynatable");
// Get a new row based on the prototype row
var prot = master.find(".prototype").clone();
prot.attr("class", "")
prot.find(".id").attr("value", id);
master.find("tbody").append(prot);
});
// Remove button functionality
$("table.dynatable button.remove").live("click", function() {
$(this).parents("tr").remove();
});
});
</script>
<style>
.dynatable {
border: solid 1px #000;
border-collapse: collapse;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
}
.dynatable th,
.dynatable td {
border: solid 1px #000;
text-align: center;
color: #FFF;
padding-top: 8px;
padding-right: 10px;
padding-bottom: 8px;
padding-left: 10px;
}
.dynatable .prototype {
display:none;
}
.blackTXT {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
color: #333;
text-decoration: none;
}
</style>
</head>
<body>
<table width="901" align="center" class="dynatable">
<thead>
<tr>
<th width="92" bgcolor="#787878">ID</th>
<th width="267" bgcolor="#787878">descripción</th>
<th width="120" bgcolor="#787878">cantidad</th>
<th width="136" bgcolor="#787878">precio unidad</th>
<th width="50" bgcolor="#787878">IVA</th>
<th width="73" bgcolor="#787878">total</th>
<th width="131" bgcolor="#787878"><button class="add">Add</button></th>
</tr>
</thead>
<tbody>
<tr class="prototype">
<form name="form" ><td bgcolor="#F8F8F8">
<input type="ee" class="id" value="<?php echo $referencia?>" size="10" /></td>
<td bgcolor="#F8F8F8"><input type="text" id="descripcion[]" size="40" /></td>
<td bgcolor="#F8F8F8"><input type="text" class="number" style="width: 100px;"/></td>
<td nowrap bgcolor="#F8F8F8"><input type="text" class="number" style="width: 100px;"/>
<span class="blackTXT">€</span></td>
<td bgcolor="#F8F8F8"><span class="blackTXT">21%</span>
<td nowrap bgcolor="#F8F8F8"><span id="result"></span> <span class="blackTXT">€</span>
<td bgcolor="#F8F8F8"><button class="remove">Remove</button></form>
</tr>
</table>
</body>
</html>