I have created a webform hook (using hook_form_alter) which searches for a particularly named input and appends an ID for JS code to make changes on the front end.
It works fine however I have come across an issue where if that input is made part of a fieldset, it can no longer find it. This is to do with how the $form array is rearranged to include children inputs in the fieldset array.
My question is: how do I find an element by name regardless of whether it is part of a fieldset or not?
This is the code I'm using, which works fine for parent level inputs but not when it is part of a fieldset. How do I get this to work where I don't need to know what the fieldset is called (because I won't always know).
function MODULE_form_alter(&$form, &$form_state, $form_id){
$form['submitted']["certain_name"]['#default_value'] = '';
$form['submitted']["certain_name"]['#attributes']['id'] = 'new-id';
$form['submitted']["certain_name"]['#ajax'] = array(
'event' => 'change',
'callback' => 'module_js_lookup(this.value)'
);
}