Morning!
I'm trying to get an input value populated based on the change in a select box, so the user selects a code and the amount is populated, I need the select box to keep it's value so I can't use the value of that onchange.
I am using a post request in the JS to get this value but can't get it too work and am exhausting options trying to find an answer.
The code is below:
<input id="amount" />
<select id="product" onChange="amountCalc()">
<option value="111">111</option>
<option value="222">222</option>
</select>
<script>
function amountCalc() {
var x = document.getElementById("product").value;
$.post('lib/amount.php', { code: +x+ }, function(result) {
document.getElementById("amount").value = result;}
</script>
The PHP page expects the code parameter and returns a value which should populate the amount field.
Any help would be great, javascript noob here :(