Hi,
I have created a simple webform which have two select fields. I want that when user select first select option then second select box is updated with values relevant to selected option.
I have created a custom form and tried using form AJAX property. This work fine but the only issue is that when I change any value then it still sends a default value rather than selected value.
I think the problem is with form_state but I could be wrong.
function apply_now_form_webform_client_form_69_alter(&$form, &$form_state) {
$options = _apply_now_get_car_makes_dropdown_options();
$selected = isset($form_state['values']['car_make']) ? $form_state['values']['car_make'] : key($options);
$form['submitted']['car_make']['#options'] = $options;
$form['submitted']['car_make']['#default_value'] = $selected;
$form['#submit'][] = 'your_submit_handler';
$form['submitted']['car_make']['#ajax'] = array(
'callback' => 'apply_now_dependent_dropdown_callback',
'wrapper' => 'dropdown-second-replace',
'method' => 'replace'
);
$form['submitted']['car_model']['#prefix'] = '<div id="dropdown-second-replace">';
$form['submitted']['car_model']['#suffix'] = '</div>';
$form['submitted']['car_model']['#options'] = _apply_now_get_car_model_dropdown_options($selected);
$form['submitted']['car_model']['#default_value'] = isset($form_state['values']['car_make']) ? $form_state['values']['car_make'] : '';
}
In the second last line in code, you will n otice that $selected is passed but this is always the first value in $options rather than what user selected.
Thanks
I can fix it. I ready begin now.
======================================================================================================================================================