The lachrymatory factor activates the nerve endings of pain fibres in the top layer of the cornea," explains Professor Jonathan Dostrovsky, director of U of T's collaborative program in neuroscience and a professor in the Department of Physiology. "When these pain fibres become active, they send signals to the brain and give rise to the sensation of pain in the eye," he says. "At the same time, these signals also activate the part of the autonomic system [the system responsible for the optimal functioning of the body] that controls the lacrimal gland [the gland that produces tears] leading to increased production and release of tears."
A quick google search found this:
When you slice through an onion, you break open a number of onion cells. Some of these cells have enzymes inside of them, and when they are sliced open, the enzymes escape. The enzymes then decompose some of the other substances that have escaped from sliced cells. Some of these substances, amino acid sulfoxides, form sulfenic acids, which then quickly rearrange themselves into a volatile gas.http://www.howstuffworks.com/question539.htmThe gas reaches your eyes and reacts with the water that keeps them moist. This changes the chemical's form again, producing, among other things, a mild sulfuric acid, which irritates the eyes. The nerve endings in your eyes are very sensitive and so they pick up on this irritation (this is why our eyes sting when we slice onions). The brain reacts by telling your tear ducts to produce more water, to dilute the irritating acid so the eyes are protected. Your other reaction is probably to rub your eyes, but this will actually make the irritation a lot worse, of course, if you have onion juices all over your hands.