ために shows the purpose for something (taken from grammar page): 「私は着替える為に家に帰った。」 I went home in order to change my clothes.
ように shows a goal/desired end - it is also a purpose, but you use ように when the purpose is not guaranteed. かぜをひかないようにはやくねてください Please go to sleep early in order to not (so you don't) catch a cold
Here, the purpose/goal is not catching the cold, although the action (going to bed early) cannot guarantee it. In other words, whether or not the subject will catch a cold is not entirely controlled by the subject.
I am in a rush, so this description may be a bit lacking, but I hope it helps!