console.log(sToPageId); has nothing to do with navigation !!
You could replace console.log with alert function.
The goal here is to check whether sToPageId is calculated correctly.
Another solution - use debugger. So when you would have console opened it would stuck on line with debugger. Debug it !