is it possible here to get the value using getElementByClassName and what should i put inside the parseFloat for the sum portion ?
The idea here is to get the sum amount from each checkbox checked and calculate the total.
I cannot use external libraries so only pure javascript selectors here and I cannot change anything within the while echo statement.
<?php
include_once('database_conn.php');
$sqlCDs = 'SELECT CDID, CDTitle, CDYear, catDesc, CDPrice FROM nmc_cd b inner join nmc_category c on b.catID = c.catID WHERE 1 order by CDTitle';
$rsCDs = mysqli_query($conn, $sqlCDs);
while ($CD = mysqli_fetch_assoc($rsCDs)) {
echo "\t<div class='item'>
<span class='CDTitle'>{$CD['CDTitle']}</span>
<span class='CDYear'>{$CD['CDYear']}</span>
<span class='catDesc'>{$CD['catDesc']}</span>
<span class='CDPrice'>{$CD['CDPrice']}</span>
<span class='chosen'><input type='checkbox' name='CD[]' value='{$CD['CDID']}' title='{$CD['CDPrice']}' /></span>
</div>\n";
}
?>
<p style="color: red; font-weight: bold;">I have read and agree to the terms and conditions
<input type="checkbox" id="termsChkbx" onchange="isChecked(this,'sub1')"/></p>
JS:
function isChecked(chosen) {
var number = parseFloat(document.getElementsByClassName('CDPrice')[0].innerHTML);
if(chosen.is(':checked')) {
sum = sum + parseFloat(????);
} else {
sum = sum - parseFloat(????);
}
$('#total').???('CDPrice')[0].innerHTML(sum.toFixed(2));
}