I have a form where the user inputs a quantity from 1 to 10, and a readonly text field where I need to output a string with the calculated price. Could also be another king of container, but since the position is inside a formatted cell, I'd prefer not to use a div. As told, anything is inside a form to post values (there's a captcha too) to a php file for the purchase process. Here is my code as far as is concerned:
function calculatePrice() {
var form = document.getElementById('buy_form');
var num_pieces = parseInt(form.elements.number_select.value);
var price_for_1 = 9.90; //I know, hardcoded is worst, I'll take it from the DB later on
var totalprice = price_for_1 * num_pieces;
document.getElementById("total_price").innerHTML = "Total price: \u20AC " + totalprice;
}
<form method="post" id="buy_form" action="buy.php">
<select name="numberselect" id="number_select" onChange="calculatePrice()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input type=text class="totalprice" id="total_price" style="border: none" readonly>
//a captcha image
//a captcha input field
//a submit button
</form>
The function simply does not output anything in the readonly text field. What am I missing?