A variational approach to chaotic dynamics in periodically forced nonlinear oscillators