I have a small form that calculates a shipping cost, which is all working fine. I want the user to click Book Now
and the fields are then populated.
All the fields have been populated correctly, its just the cost calculation doesn't populate on the form.
This is my code for calculting the cost
var values = [
[20,25,35,40],
[36,42,50,56],
[42,56,52,68],
[60,70,68,72],
];
function updateValue() {
var fromCountry = document.querySelector('input[name="from_country"]:checked').value;
var toCountry = document.querySelector('input[name="to_country"]:checked').value;
var totalValues = values[fromCountry-1][toCountry-1];
var quantity = document.querySelector('select[name="number"]');
var x = parseInt(quantity.value, 10);
if(fromCountry && toCountry) {
document.getElementById('cost').value = (totalValues * x);
}
}
This is the html
<input type="text" id="cost" name="cost" value="0" disabled="disabled" />
Then the other form looks like this:
<label for="cost">Estimated cost</label>
<input type="text" id="cost" name="cost" value="<?php echo $_POST['cost'];?>">
All the other fields populate fine but the cost one doesn't for some reason.