I have created a content type "Type A" and added three fields to content type. I want to display value in third field equal to (value of first field - value of second field).
I want to implement the same using ajax functionality. I have created a custom module and alter the "node form" and add ajax to field 1 but ajax is not working on change event of textfield.
Code Snippet:
function employee_login_form_alter(&$form, &$form_state, $form_id){
$form['field_total_value']['#prefix'] = '<div id="calculate-total-value">';
$form['field_total_value']['#suffix'] = '</div>';
$form['field_value_first']['#ajax'] = array(
'callback' => 'employee_login_ajax',
'wrapper' => 'calculate-total-value',
'method' => 'replace',
'event' => 'change',
);
$form['field_value_first']['und'][0]['#ajax'] = array(
'callback' => 'employee_login_ajax',
'wrapper' => 'calculate-total-value',
'method' => 'replace',
'event' => 'change',
);
}
function employee_login_ajax(&$form, &$form_state) { //print_r($form); exit;
print_r($form_state['values']);
}
Thanks in advance.