If I'm using the following code to make a calculation and assign it to a variable, how would I go about making that variable accessible anywhere on the html page? I thought that simply declaring it as result from elsewhere on the page = (quantity * product).toFixed(2) ;would then allow me to output it to the console using console.log('result from elsewhere on the page is p * q ' + result);
but when I do that I get result from elsewhere on the page is p * q [object HTMLSpanElement] as the output
<script>
$('#quantity,#product').bind('change keyup', function () {
var product = $('#product').val(),
quantity = parseInt($('#quantity').val(), 10),
result = (quantity * product).toFixed(2);
$('#result').text(result);
console.log('Testing console');
console.log('result is p * q ' + result);
console.log('quantity is ' + quantity);
});
</script>
note: the first output console.log('result is p * q ' + result);
works fine and outputs result is p * q 98.00 it's only when I try it from outside of the that I get the result from elsewhere on the page is p * q [object HTMLSpanElement] returned.
thanks for any help with this.