I have a webform created using the admin panel and would like to change one of its textfield values on click of a button. I have attempted doing this from hook_form_alter. I have given the wrapper name 'changeText' for this textfield from admin panel.
function fence_quote_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'webform_client_form_1'){
$form['buttons']['fence_quote'] = array(
'#type' => 'button',
'#value' => t('Get online estimates'),
'#ajax' => array(
'callback' => 'fence_quote_form_callback',
'wrapper' => 'changeText',
),
);
$form['field_meters']['#prefix'] = '<div id="changeText">';
$form['field_meters']['#sufix'] = '</div>';
}
}
function fence_quote_form_callback($form, &$form_state) {
$form_state['values']['field_meters']['und'][0]['value'] = '111';
return $form['wrapper'];
}
The problem is I can't update 'meters' value using AJAX callback as it is a field created from admin panel and not from hook_form_alter. However if I place
$form['submitted']['meters']['#default_value'] = '111';
outside of the callback it works on page refresh. How can I do this?
As requested by @kamal-oberoi I'm uploading a screenshot of my full code.