Blood electrolyte imbalance can cause leg cramps. This may or may not be related to your passing out immediately afterwards. You need to see a doctor right away for the sake of your health, and for the safety of others. Passing out while driving, for example, can cause serious injuries including death.