Fixing the ordering of the calls to ensure that javascript function is called when the view is loaded