I try to get the values of several fields and add them together, and during testing I am having problems. I have this code:
var count;
function calculate() {
jQuery.noConflict();
count = 0;
jQuery('.calculate').each(function() {
var currentElement = jQuery(this);
var value = currentElement.val();
var count = count + value;
alert(count);
});
}
I entered the value "9" in my first field, and when the first warnings fire, I get "undefined9"; all other values are currently set to "0"; when it fires again, I always get "undefined0".
Why do I get the "undefined" bit and why does it only return the current field and not add them together?
source
share