jquery UI dialog and html checkbox imput

jquery UI dialog and html checkbox imput

Hi to all.  I want to use jquery UI dialog and  i have placed a checkbox on div that should be displayed as a dialog.
   
<input type="checkbox" id="cb_auto_save"  name="cb_auto_save" onclick="set_state(this)"    >
set state function looks like this for the moment 

 function set_state(obj)
{  
if($('#cb_auto_save').val()== "n")
{ $('#cb_auto_save').val("y") ;}
else
{  $('#cb_auto_save').val("n");} 
}
when i try to check the  checkbox everything works fine , except the fact that after the function ends its execution , the checkbox is   set back to unchecked state. I have tested this  functionality without jquery dialog  in same html context   , it works fine checkbox  stays checked. 
Thanks in  advance