How to add onclick event to a link?

I need to create a link, which when clicked should be able to set a session variable.

I have used l() function to create the link and tried this but this is not working.

'name' => l(t($  n['name']),'edit_details',array('attributes' => array('onclick' =>$  _SESSION['id']=$  n['id'] ))),