How to set default value of select list field on add node form? I am trying to set the default value of a select list field on a node add form. The field name attribute in the HTML of the form is:

field_state[und]


The ID of the add form is:

local-affiliate-node-form


I created a little module to try to do this. It just has this code in it:

function MODULENAME_form_alter(&amp;$form, $form_state, $form_id) {
    if($form_id == 'local-affiliate-node-form'){
        $form['field_state']['und']['#value'] = 17;
    }
}


I enabled the module and cleared cache but it doesn't appear to work. I also tried these lines inside the IF statement:

$form['field_state']['und']['value'] = 17;
$form['field_state']['und']['value']['#value'] = 17;
$form['field_state']['und']['#default_value'] = 17;


In case you're wondering, I can't use the Drupal interface to set the default value because eventually that "17" will be dynamic, so it will change depending on what the user clicks and I will use a string in the URL in place of a static number.

Thanks for any help!
If you need "code" way you need set default value like this.

$form['field_name']['und']['#default_value'][0] = "1"


"1" -  its number of element which you want set default.

I use that when i need set programaticaly default value for field which use term reference.