i have this code, i want when input field #amount is add, jquery will get the value, multiply it with 0.20 and add the value to #agentfee. The value of #agentfee will be used to insert value in sql table using php code. I dont know why my code is not working
HTML
<label for="amount">Rent Amount</label>
<input type="number" id="amount" name="amount" placeholder="500,000">
<label for="agentfee">Agent fee N</label>
<input type="Number" id="agentfee" name="agentfee" value="" readonly><br>
JS
$('#amount').change(function() {
var inputValue = $("#amount").val();
agentFee = inputValue * 0.20;
$('#agentfee').val=('agentFee');
});
4
Answers
You don’t need the ticks around agentFee, or the equals. It should be
As @Calvin pointed out already you need to change your
$('#agentfee').val()
line:Try this :
$(‘#amount’).change(function() {
i hope it was useful
Your
overrides the
val
function of$('#agentfee')
with the text ofagentFee
. Instead, you wanted to callval
and pass a value, like$('#agentfee').val(yourvalue);
. This is a simplified solution (I have changed the event fromchange
toinput
to make sure the input is more responsive. If you strongly prefer thechange
event, then let me know)