how to let a form field be hidden and at the same time the value be able to acces the id using javascript?
Try this: 

$form['hidden'] = array(
 '#type' =&gt; 'hidden',
 '#value' =&gt; 'Your_value',
 '#attributes' =&gt; array('id' =&gt; array('your_id')),
);


Now using javascript or jquery you get the value of the hidden field. 

In jquery:  jQuery("#your_id").val();