To reap the benefits of onion juice, use the juice of a raw onion. This is when it contains a variety of organic sulphur compounds.
These are partly destroyed by heat, if you cook the onion.
What about the smell?
Onions are notorious for having a strong odour, and this certainly will apply if putting onto your hair.
Should you attempt to put onion juice on your hair and scalp, rinse with cold water afterwards. Then wash with soap and rinse with warm water.