Using JS to access a form element where the id is an array
Posted: Wed Apr 29, 2009 6:19 pm
Hello,
I have generated numerous form fields using PHP and can happily pass the values (arrays) I require by form post. I wanted to do some calculations on the fly to display subtotals etc with a js function but am unsure of the syntax to access an id that is an array.
For example, I would like to have a running total based on the sum of elements in orderQty[] and update a field with id="tlOrderQty" but I am unsure of the syntax.
Grateful for any assistance, Andrew
I have generated numerous form fields using PHP and can happily pass the values (arrays) I require by form post. I wanted to do some calculations on the fly to display subtotals etc with a js function but am unsure of the syntax to access an id that is an array.
For example, I would like to have a running total based on the sum of elements in orderQty[] and update a field with id="tlOrderQty" but I am unsure of the syntax.
Code: Select all
<?php
foreach ($_SESSION['taxonomies'] as $taxonomy)
{
$desc = explode('^',$taxonomy);
echo '<tr>';
echo '<td>'.$desc[0].'</td>';
echo '<td>'.$desc[1].'</td>';
echo '<td>'.$desc[2].'</td>';
echo '<td><input type="text" id="orderQty[]" name="orderQty[]" onchange="total_order();"></td>';
echo '<td><input type="text" id="unitPrice[]" name="unitPrice[]</td>">';
echo '<td><input type="text" id="extPrice[]" name="extPrice[]"></td>';
$i = $i + 1;
}
?>