I have a dropdown select box and a textarea. I want to update the textarea each time I change the value of the dropdown select box. The value of the textarea will come from the database and will depend on the value of the dropdown select. I was able to update the textarea each time the select box is changed. However, when I add something to the value in the textarea or change it to something, I still get the same value when it was changed onselect when I submit the form:
<?php
function mymodule_form_builder($form, $form_state) {
$form = array();
$form['term'] = array(
'#title' => t("Choose a term"),
'#type' => 'select',
'#options' => array(
'one' => 'Option 1',
'two' => 'Option 2',
'three' => 'Option 3'
),
'#ajax' => array(
'callback' => 'mycallback',
'wrapper' => 'textarea-div',
),
);
$form['mytextarea'] = array(
'#title' => t('Keywords For This Term'),
'#type' => 'textarea',
'#prefix' => '
',
'#suffix' => '
'
);
if (!empty($form_state['values']['term'])) {
$form['mytextarea']['#value'] = datafromdatabase($form_state['values']['term']);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function mycallback($form, $form_state) {