It depends on the scope of variable sc. Is sc global? You can do the following:
var scInput = 'whatever';
var total;
function recalculateTotal(sc) {
var total = 0;
//basically find every selected seat and sum its price
sc.find('selected').each(function() {
total += this.data().price;
});
return total;
}
total = recalculateTotal(scInput);
function call(a) {
window.location.replace("Demo2.jsp?name=" + a);
}
call(total);
Your original code sample is fine so long as the variable sc and call(); are in the same scope. I think you might be confused by parameters vs. arguments. In your recalculateTotal function you define a parameter called 'sc'. However, when you call that function you need to send in an argument (the value of sc). So your original example is correct in the following instance
var sc = 'your-value'
function recalculateTotal(sc) {
var total = 0;
//basically find every selected seat and sum its price
sc.find('selected').each(function() {
total += this.data().price;
});
return total;
}
function call() {
var a = recalculateTotal(sc);
window.location.replace("Demo2.jsp?name=" + a);
}
call(sc);
It is correct in the above example because there exists a variable sc in the global scope that the call function has access to. The same is also true for this example:
var sc = 'your-value'
function recalculateTotal() {
var total = 0;
//basically find every selected seat and sum its price
sc.find('selected').each(function() {
total += this.data().price;
});
return total;
}
function call() {
var a = recalculateTotal();
window.location.replace("Demo2.jsp?name=" + a);
}
call();
The confusion you might have is that in your example you have an argument sc in recalculateTotal(sc), and in the call method the attribute you pass I to recalculateTotal(sc) is also called sc. This is correct notation and a very common practice, but it does confuse people who are not familiar with it