So here is my problem. I have a table for a cart page and I'm trying to update the total price but for some reason it is not updating correctly. Here is my code.
This is my JS
This my HTML
Thanks!
This is my JS
Code:
function deleteSource(rowNum){
//remove selected row
choice=confirm('Are you sure you want to remove this item from your cart?');
if(choice){
$('#row'+rowNum).remove();
}
else{
return false
}
updateTotal();
}
function deleteAll(){
choice=confirm('Are you sure you want to remove all items from your cart?');
if(choice){
$('#row1').remove();
$('#row2').remove();
$('#row3').remove();
$('#row4').remove();
$('#row5').remove();
}
else{
return false
}
updateTotal();
}
function updateTotal(){
var price1 = parseFloat($('#price1').val());
var price2 = parseFloat($('#price2').val());
var price3 = parseFloat($('#price3').val());
var price4 = parseFloat($('#price4').val());
var price5 = parseFloat($('#price5').val());
var total = parseFloat( price1+price2+price3+price4+price5 );
return total;
}
Code:
<table border="0" cellpadding="10" cellspacing="0"> <tr id="row0"> <th>Item #</th> <th>Facility Name</th> <th>Item</th> <th>City</th> <th>Region</th> <th>Start Time</th> <th>End Time</th> <th>Price ($)</th> <th>Date</th> <td><a onclick="return deleteAll()">[Remove All]</a></td> </tr> <tr id="row1"> <td>1231</td> <td>Southern NB Arena</td> <td>Ice Hockey</td> <td>St. Stephen</td> <td>NB</td> <td>8:00am</td> <td>10:00am</td> <td><input type="text" id="price1" disabled="true" value="50" /></td> <td>Feb 10</td> <td><a onclick="return deleteSource(1)">[Remove]</a></td> </tr> <tr id="row2"> <td>33322</td> <td>Joes Backyard Rink</td> <td>Ice Hockey</td> <td>St. Stephen</td> <td>NB</td> <td>8:30am</td> <td>11:30am</td> <td><input type="text" id="price2" disabled="true" value="70" /></td> <td>Feb 10</td> <td><a onclick="return deleteSource(2)">[Remove]</a></td> </tr> <tr id="row3"> <td>3433</td> <td>Tide Arena</td> <td>Ice Hockey</td> <td>St. George</td> <td>NB</td> <td>9:00am</td> <td>10:00am</td> <td><input type="text" id="price3" disabled="true" value="60" /></td> <td>Feb 10</td> <td><a onclick="return deleteSource(3)">[Remove]</a></td> </tr> <tr id="row4"> <td>6334</td> <td>Dipper Habour Centennial Arena</td> <td>Ice Hockey</td> <td>Dipper Harbour</td> <td>NB</td> <td>8:45am</td> <td>11:00am</td> <td><input type="text" id="price4" disabled="true" value="55" /></td> <td>Feb 10</td> <td><a onclick="return deleteSource(4)">[Remove]</a></td> </tr> <tr id="row5"> <td>54543</td> <td>Down East Iceplex</td> <td>Ice Hockey</td> <td>Machias</td> <td>NB</td> <td>8:00am</td> <td>10:00am</td> <td><input type="text" id="price5" disabled="true" value="100" /></td> <td>Feb 13</td> <td><a onclick="return deleteSource(5)">[Remove]</a></td> </tr> <tr><hr></tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td>Total:</td> <td><input type="text" id="total" disabled="true" value="updateTotal()"/></td> <td> </td> <td><input type="submit" value="Proceed to Checkout" /></td> </tr> </table>
Comment