RMC is correct; any function referenced by an
on...
attribute within the HTML
needs to be a global function, not a function nested within another function.
You need to move the function outside of the jQuery event handler:
$(function(){
var userId = <?php echo isset($_SESSION['user_id']) ? $_SESSION['user_id'] : 0; ?>;
updateCartBadge(userId);
});
function proceedToBilling() {
var referenceNumber = "<?php echo $_SESSION['reference_number']; ?>";
var shippingCost = "<?php echo $_SESSION['shipping_cost'];?>";
window.location.href ="billing_address.php?ref=" + referenceNumber + "&shipping=" + shippingCost;
}
NB: Read the jQuery documentation:
jQuery offers several ways to attach a function that will run when the DOM is ready. All of the following syntaxes are equivalent:
$( handler )
$( document ).ready( handler )
$( "document" ).ready( handler )
$( "img" ).ready( handler )
$().ready( handler )
As of jQuery 3.0, only the first syntax is recommended; the other syntaxes still work but are deprecated.
You are using a deprecated syntax (
$(document).ready(function() { ... });
); you should replace that with the recommended syntax (
$(function() { ... });
).