Onions are best kept in cool dark places such as a basement, cellar, garage, fridge, etc.
As long as you keep the onions in a cool dark place they are preserved for longer than they would be if they were kept out at room temperature in the light or sunlight.
You can also slice the onions up and then either refrigerate the cut up onions or freeze the cut up onions to preserve them.
When you cut up the onions place them in a Ziploc bag or freezer safe container and either freeze them or refrigerate them.
Refrigerating the cut up onions helps them last for 7 days and in the freezer they will last for 6 months to a year.
You can also refrigerate whole onions as well as freeze whole onions and they will also keep just fine.