Forum Moderators: open
<input type='text' name='boat_loa[$i]' id='boat_loa$i' size=8 maxlength=8 placeholder='Feet' onkeyup='calcBoatCost($i)' />
<input type='text' name='boat_beam[$i]' id='boat_beam$i' size=6 maxlength=6 placeholder='Feet' onkeyup='calcBoatCost($i)' />
<input type='text' name='boat_area[$i]' id='boatAreaResult$i' /> <select name='product' id='prod_id$i' onchange='calcBoatCost($i)'>
// iterate on each product in the query:
<option value=$product_id>$product_id $product_name $standard_price</option <div id='uPrice$i'>$i 0.00</div>
<input type='text' name='boat_cost[$i]' id='boatCostResult$i' /> var unitPrice = document.getElementById('uPrice' + rowNumber).value;
alert ('UP: ' + unitPrice ); <form method='post' action='$_SERVER[PHP_SELF]'>
// snip
<table>
<tr><th>LOA</th><th>Beam</th><th>Draft</th><th>product</th><th>test</th><th>Cost</th></tr>
// loop for multiple lines
<td><input type='text' name='boat_loa[$i]' id='boat_loa$i' size=8 maxlength=8 placeholder='Feet' onkeyup='calcBoatCost($i)' /></td>
<td><input type='text' name='boat_beam[$i]' id='boat_beam$i' size=6 maxlength=6 placeholder='Feet' onkeyup='calcBoatCost($i)' /></td>
<td><input type='text' name='boat_area[$i]' id='boatAreaResult$i' /></td>
<td><select name='product' id='prod_id$i' onchange='calcBoatCost($i)'>
// MySQL call to get products and loop through each found, $i is the counter
<option value=$product_id>$product_name</option>
// end of options loop
<td><div id='uPrice$i'><b>$i 0.00</b></div></td>
<td><input type='text' name='boat_cost[$i]' id='boatCostResult$i' /></td>
</table>
<script type=\"text/javascript\" src=\"//code.jquery.com/jquery-1.10.2.js\"></script>
<script type=\"text/javascript\">
function calcBoatCost(rowNumber) {
var boat_loa = document.getElementById('boat_loa' + rowNumber).value;
var boat_beam = document.getElementById('boat_beam' + rowNumber).value;
var prod_id = document.getElementById('prod_id' + rowNumber).value;
alert ('Prod ID: ' + prod_id );
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(\"uPrice\" + rowNumber).innerHTML = this.responseText;
}
};
var str = prod_id;
alert ('STR: ' + str );
xmlhttp.open(\"GET\",\"get_product_price.php?q=\"+str,true);
xmlhttp.send();
var boatArea = parseFloat(boat_loa) * parseFloat(boat_beam);
alert ('Area: ' + boatArea );
if (!isNaN(boatArea)) {
document.getElementById('boatAreaResult' + rowNumber).value = boatArea;
}
var unitPrice = document.getElementById('uPrice' + rowNumber).value;
alert ('UP: ' + unitPrice );
var boatCost = boatArea * parseFloat(unitPrice) ;
if (!isNaN(boatCost)) {
document.getElementById('boatCostResult' + rowNumber).value = boatCost;
}
var numRows = '$numRows';
var x = 1;
var BoatTotal = 0;
while( x <= numRows) {
var boat_cost = document.getElementById('boatCostResult' + x).value;
if (!isNaN(parseFloat(boat_cost))) {
BoatTotal += parseFloat(boat_cost);
}
x++;
document.getElementById('boatTotal').value = BoatTotal;
var grandTotal = BoatTotal;
document.getElementById('grandTotal').innerHTML = '$'+grandTotal.toFixed(2);
}
}
</script>
$price_query = "SELECT product_prices.*,
FROM show_product_prices
WHERE product_id = $q
";
$price_result = query($price_query);
$PriceArray = fetch_array($price_result);
$standard_price = $PriceArray['standard_price'];
echo "$standard_price";
var formNode = document.getElementByID('myForm')
formNode.getElementByID('myInput'). addEventListener(..... //or whatever code you want
var formNode = document.getElementByID('myForm')
var formChildren = formNode.children
for (let i = 0; i < formChildren.length; i++) {
console.log(formChildren.children[i].tagName);
}
var selectNodes = document.querySelectorAll('select .prod_id') // selects select tags with a class name .prod_id
for (let i = 0; i < selectNodes.length; i++) {
selectNodes[i].addEventListener('change', calcBoatCost)
}