I'm trying to multiply and input amount by 3.5%, Can anyone give me any ideas how to do it?
$("#invest_amount").keyup(function() {
$('#fee').val($('#invest_amount').val() + 3.5);
});
You need to parse the input first then use * to multiply, not +, for example:
$("#invest_amount").keyup(function() {
$('#fee').val(parseFloat($('#invest_amount').val()) * .035);
});
or...
$("#invest_amount").keyup(function() {
$('#fee').val(+$('#invest_amount').val() * .035);
});
.val() returns a string, so you need to use + or praseFloat() to convert it to a number first
$('#fee').val((+$('#invest_amount').val() * .035).toFixed(2));+ because * will do it for you, e.g. $('#fee').val(($('#invest_amount').val() * .035).toFixed(2));You need to parse the value first:
var value = parseFloat($('#invest_amount').val());
if (!isNaN(value)) {
$('#fee').val(value * 0.035);
} else {
alert('The entered value is not a valid number');
}
Knowing mathematics, and the significance of mathematical symbols, seems to be a basic prerequisite for your problem. Read more about mathematics here: http://en.wikipedia.org/wiki/Mathematics
+in your code instead of multiplication.