Hello I am begginner in php.
I create a ecommerce site .
first I fetch all information from database. all is going correct but I have problem in quantity input
when I insert quantity value then the total calculate in total .
I use js but I don't know to fetch the price value from database and store in javascript
variable.
the code is :
<?php
echo "ISBN:". $row['isbn']."<br/>";
echo "Publisher:". $row['publisher']."<br/>";
echo "Year:". $row['year']."<br/>";
echo "Price:". $row['price']."<br/>";
?>
Qty : <input type="text" name="qty1" id="qty"/><br>
Total : <input type="text" name="total" id="total"/>
<a href="javascript:sumInputs()">Sum</a>
<script>
window.sumInputs = function() {
var inputs = document.getElementsByTagName('input'),
result = document.getElementById('total'),
sum = 0;
var q = $row['price']; //how to resolve this line
for(var i=0; i<inputs.length; i++) {
var ip = inputs[i];
if (ip.name && ip.name.indexOf("total") < 0) {
sum = parseInt(ip.value)*q || 0;
}
}
result.value = sum;
}
</script>