Hello,
I have the following jQuery script:
$(document).ready(function() {
$.ajax({
url: 'temp.ajax.php',
type: 'GET',
success: function(data){
$("#total_plus_aditional").val(data);
}
});
tempTotal = parseFloat($("#total_plus_aditional").val());
$("#cost_valoare").change(function(){
var sum = parseFloat(tempTotal) + parseFloat($("#cost_valoare").val());
$("#total_plus_aditional").val(sum);
});
});
Now, here's what I want to do: the temp.ajax.php returns a float value. First, that float value is assigned to an input field in the html so the user can see the number. Then, if the user enters a number in another input field, I would like to make the sum of those two numbers and rewrite the value in the first input field.
The problem is that if I write a number in a second field, the content of the first field (with the float number returned by ajax call) turns to NaN.
Why is this happening?
P.S. I'm saving the value returned by the ajax call in a separate variable because I would like to have the same value if the user changes his mind and enters another value in the second field after he already entered one.