Get field value by machine name I developed a custom module in Drupal 7. I asked a similar question here: 
Drupal 7 Get field value by machine name and pass to javascript

But the difference in this question is, instead of a taxonomy term, I want to get the field value of a regular text field.

Here is the code that I use to get the field value of a taxonomy term to pass to javascript, which currently resides in my theme's hook_process_page function:

if ($node = menu_get_object('node')) {
  $tid = $node-&gt;field_test['und'][0]['tid'];
  $term = taxonomy_term_load($tid);
  drupal_add_js(array('mymodule' =&gt; array('test' =&gt; $term-&gt;name)), 'setting');
}


Some things that I can see might ned to be changed right away are "tid," "taxonomy_term_load."

How can I change this code to instead get the text value of a field instead of a taxonomy term, to pass to mymodule? 

EDIT:

Per a suggested change, I've modified the code, though I'm not sure this is what was meant:

if ($node = menu_get_object('node')) {
  $fieldValue = $node-&gt;field_test['und'][0]['value'];
  $term = taxonomy_term_load($fieldValue);
  drupal_add_js(array('jsblock' =&gt; array('test' =&gt; $fieldValue-&gt;name)), 'setting');
}


The in response to Drupal.settings.jsblock.test, the console outputs null.

Here is the Drupal notice:



Devel results:



How can I get the field value and pass it to my jsblock module?
For text fields you can use

$value = $node-&gt;field_my_field_name['und'][0]['value'];


or, if you want sanitized value, use ['safe_value'].