I have a question of dynamic elements in php loaded through mysql. The PHP code is as follow
<?php
$query = "SELECT * FROM `fee_table` WHERE fee_class_id = 6 ";
$result = mysql_query($query) or die(mysql_error());
// Print out the contents of the entry
echo "<table width='400'>";
echo "<th width='10' scope='col'>Qty</th>";
echo "<th width='265' scope='col'>Type of Fixture or Item</th>";
echo "<th width='25' scope='col'>Fee</th>";
echo "<th width='100' scope='col'>Total</th>";
while($row = mysql_fetch_assoc($result)){
$array[] = $row['fee_amount'];
$feeKeys = array_values($array);
echo "<tr>";
echo "<td><input size='5'type='text' on='cal_electic_permit()' id=";echo $row['fee_desc'];" />";
echo "</td>";
echo "<td>";
echo $row['fee_desc'];
echo "</td>";
echo "<td>";
echo $row['fee_amount'];
echo "</td>";
echo "<td><input name='electric_fee' type='text' id='electric_fee' size='11' />";
echo "</td>";
echo "</tr>";
}
echo "</table>";
//$recfee =$array[0];
//print($recfee);
//print_r($array);
foreach($array as $fee){
} //makes counting variable and assigns array value to it
for ($i =1; $i <= mysql_num_rows($result);$i++){
echo ${"qty_{$i}"}=$fee;
echo '<br/>';
}
?>
The js code is to get the element id and then calculate the cost of each row on the table. The problem that I am haveing is getting the js element to work.
<script type="text/javascript">
function cal_electic_permit()
{
numRec = eval(document.permit.Receptacles.value)
recfee = eval(document.permit.qty_1.value)
//cost for commerical new construction permits
var recTfee =numRec * recfee;//get value of the fee from php database query
document.electric_fee.value = recTfee;
}
</script>
THe problem I believe is that the php html element to call the js function is not working right.
I welcome anyone imput.
Jon