Hi, I also having the same problem for the last few months, but i finally found a solution for it. first i'll tell what is the problem & how it happen to you galaxy phone.
whenever happen to this wifi issue is when u have updated the firmware of the phone original version 4.1.1 to 4.1.2 jelly bean, the update will cause ur phone wifi connect go crazy, and
this only happen to some of galaxy phone not all the galaxy phone. nothing going to help even u reset to the factory, bcoz the firmware of ur phone is already updated to 4.1.2 jelly bean. in this state
nothing u can do to solve the wifi problem, bcoz the core of the wifi processes has already been modified.
the only solution for the wifi is using the third party app to support the wifi chip in the galaxy phone. in order to do that, first u must go to the Play Store and then goto the Search for
wifi connector library make from farproc. download & install the app, then the app will automatically run as a background process, once is done, now u should be able to connect to any wifi hotspot
i hope the above solution will help u.