Those classified as sweet varieties will keep in the range of one to two weeks and cooking onions will keep about three to four weeks when stored at room temperature in a dry area. Often a mesh type of bag works well for storing onions. Keeping them in a cool, dark place will also be beneficial.
For leeks or green onions and to keep whole cooking or sweet onions longer, put them in the refrigerator in a container by themselves. Onions have a tendency to take on moisture and odors from some fruits or vegetables that they are stored with and that would reduce their shelf life.
After cutting an onion to use part of it, tightly wrap the unused part that you are keeping for later and store it in the refrigerator, again isolating it from other fruits and vegetables.