Form Load and Unload
Lets try this method 

on your form 

function form_example_form($form, &amp;$form_state) {
  $name = 'myname';
  $value = 'nikhil';
  variable_set($name, $value);
  // Your form elements goes here ...   
}

function form_example_form_submit($form, &amp;$form_state) {
  $name = 'myname';
  $myname = variable_get($name, $default = NULL);
  echo $myname; // will print nikhil
  variable_del($name);

}


As i dont know any Form Unload event i will do 

drupal_add_js("jQuery(document).unload(function() { 
//make an AJAX call to clear the value });", 'inline');


in javascript 

Good luck.