Updating javascript to capture variable changes