OnClick Script for Sidemenu item

Is there a way to configure a onClick script for a menu bar item.

For e.g.

when clicked on item 'Test 1', write Test 1 to a string parameter

when clicked on item 'Test 2', write Test 2 to a same string parameter

Regards,

Sameer