When you're craving onions you are usually suffering from a nutrient deficiency.
The onions contain the nutrients that you could be deficient in and so you are craving onions.
Onions contain a lot of dietary fiber, Vitamin B6, Folate, Potassium and Manganese, and a very good source of Vitamin C.
If your onion craving continues then you should let your doctor know that you're suddenly craving onions and you can be tested for nutrient deficiencies.
Most times the deficiency is not serious and eating the onions will give you those nutrients and onions are also very health for you.
But it would be good to get tested for the nutrient deficiency.