Submit upon close - undefined error