im really sorry i dont know how to acces this one: Im trying to have a button that when click, computes the total amount from an element which is an array since it is dynamic but accessing methods dont work.
Here is my javascript for adding and deleting:
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 1) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
and then i have this dynamic adding of items:
<tr>
<td>Items</td>
<td style="text-align:left;">
<INPUT type="button" value="Add New Item" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete Item" onclick="deleteRow('dataTable')" />
<TABLE id="dataTable" width="350px" >
<TR>
<TD><INPUT type="checkbox" name="chk[]"/></TD>
<TD>
<select name="ItemNo[]" id="select" value="ItemNo" >
<?php
$sql2="select * from jewelry_system.item where NumStored !='0' order by ItemName asc";
$result2 = mysql_query($sql2);
while($row2=mysql_fetch_array($result2)){
?>
<option value="<?php echo $row2['ItemNo']?>:<?php echo $row2['SalePrice']?>"> <?php echo $row2['ItemName'];?> [ Php <?php echo $row2['SalePrice'];?> Stocks Left:<?php echo $row2['NumStored'];?> ]</option> <?php } ?>
</select>
</TD>
</TR>
</TABLE >
</td>
</tr>
and by using this function to seperate my ItemNo value andthe Sale Priceof the item and then myfunction wont work of adding up that is checktotal():
function findexts(f){
f=strtolower(f);
exts=split('[/\\:]', f);
n=count(exts)-1;
exts=exts[n];
return exts;
}
function checkTotal(){
var total = 0;
var temp = 0;
var itemArray = document.trans.ItemNo;
for(var i=0;i<itemArray.length;i++){
temp = findexts(itemArray[i].value);
total += temp;
}
alert("Total Payment: "+total);
}
Can someone spare timeplease.I really need this. thank youu
function checkTotal()
{
var total = 0;
var parts = null;
// Your select input has an ID of "select", so this will iterate through each option
$('#select option').each( function () {
// The Item # and Sale Price are separated by a colon (:)
parts = $(this).val().split(':');
// Increment the total with the Sale Price of each item
total += parseFloat(parts[1]);
});
alert("Total Payment: "+total);
}
//also The item $ will iterate so try this
// The Item #,$ and Sale Price are separated by a colon (:)
parts = $(this).val().split(':');
// Increment the total with the Sale Price of each item
total += parseFloat(parts[1]);
});
alert("Total Payment: "+total);
}