I'm assuming that you want the behaviour caused by the AJAX callback to take effect on the form even if the AJAX request hasn't been made?
The best way to do this would be to move the logic out of the AJAX callback function and make all necessary form changes in the form function itself. Then in your AJAX callback you just need to return the element you're interested in. For example your code might look like this:
// Simple form presenting a dropdown which changes the value in a textfield.
function mymodule_dropdown_form($form, &$form_state) {
// If the dropdown value is set in $form_state (which happens when the form
// is re-built for an AJAX request), use that value.
if (isset($form_state['values']['dropdown1'])) {
$dropdown1_value = $form_state['values']['dropdown1'];
}
// Otherwise if the variable has already been set, use that value
else if ($variable_value = variable_get('dropdown_value', FALSE)) {
$dropdown1_value = $variable_value;
}
// Otherwise choose your default value
else {
$dropdown1_value = 1;
}
$form['dropdown1'] = array(
'#type' => 'select',
'#title' => 'Dropdown 1',
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5)),
'#default_value' => $dropdown1_value,
'#ajax' => array(
'callback' => 'mymodule_dropdown_form_callback',
'wrapper' => 'textfield-wrapper'
)
);
// Now decide on the value for the textfield.
if ($dropdown1_value == 1) {
$textfield_value = 'Value 1';
}
else if ($dropdown1_value == 2) {
$textfield_value = 'Value 2';
}
// etc...
// Now we have a definitive value for the textfield regardless of context.
$form['textbox'] = array(
'#type' => 'textfield',
'#title' => 'Text Field',
'#default_value' => $textfield_value,
'#prefix' => '<div id="textfield-wrapper">',
'#suffix' => '</div>'
);
return $form;
}
function mymodule_dropdown_form_callback(&$form, &$form_state) {
// The element is already build correctly at this point so just return it.
return $form['textbox'];
}
That's a very rudimentary example and will need a bit of massaging before it does anything useful but it should give you a place to start.