You crave onions because you have a nutritional deficiency. An overloaded liver can cause you to crave onions, broccoli and garlic. I would go to your doctor and he will have suggestions on what vitamins you should take.
1 Additional Answer
Usually when we crave a certain food, it is because we are deficient in something that food contains. A person who has a sluggish liver may crave onions because onions contain a lot of sulfur. Sulfur helps to improve liver function, which can explain an onion craving. You can find more info at: www.bodymindspiritguide.com