Can I use hook form alter to add an attribute to a webform field? I am trying to use hook form alter to add an onchange attribute to a select field but it is not working. Is it possible or is there something wrong with my module code?


function addonchange_form_alter(&amp;$form, &amp;$form_state, $form_id){
  // target a single form
  if($form_id == "webform_client_form_22"){
    $form['submitted']['company']['#onchange'] = 'changevalue';
  }
}


Thanks for any help.
You have to do something like this:

function addonchange_form_alter(&amp;$form, &amp;$form_state, $form_id){
  // target a single form
  if($form_id == "webform_client_form_22"){
    $form['submitted']['company']['#attributes']['onchange'] = 'changevalue';
  }
}