Onions contain a high amount of sulfur compounds. When you slice them, it causes cells to break apart and the release of alliinase, a particular enzyme unique to onions (and garlic plants). This enzyme reacts with sulfoxide amino acids to generate sulfenic acid, however this compound is highly unstable and will breakdown into propanethial-S oxide, a gas compound which then is dispersed into the immediate environment.
This gas wafts up slowly towards your eyes while you prepare the onions and upon contact with the tear film layer of your cornea, it reacts to produce a dilute solution of sulfuric acid. Acid in your eyes = burning and stinging = crying.
In order to avoid the propanethial-S oxide compound from forming, you can force the gas to be formed into the sulfuric acid before dispersing by providing ample amounts of water while you slice the onion (ie. under a tap of running water, or in a basin). Or you may choose to change the enzyme kinetics by freezing or chilling the onion to disable the alliinase and prevent the propanethial-S oxide from ever forming.