Ajaxly set Text Field Value with Drupal Forms API I have a text field and a ajaxified link in my form:

$form['id_number'] = array(
    '#title' =&gt; t('ID Number'),
    '#type' =&gt; 'textfield',  //textfield  
    '#suffix' =&gt; '&lt;div&gt;l(t('101-03043'), 'myid_choose_result/101-03043/1, array('attributes' =&gt; array('class' =&gt; 'use-ajax')))&lt;/div&gt;',  //ajaxified link 
    '#attributes' =&gt; array('id' =&gt; 'myid_search_id_number'),
); 


The link above calls a function myid_choose_result define in my hook menu:

function myid_menu(){
    $items = array();

    $items['myid_choose_result'] = array(      
        'page callback' =&gt; 'myid_choose_result',
        'access callback' =&gt; 'myid_user_access',
        'file' =&gt; 'myid.pages.inc',
        'type' =&gt; MENU_CALLBACK,
    );
    return $items;
}


What I want to achieve is every time the user clicks the link, the text field value will be the link's text. After doing so, I want to call a another function:

function myid_choose_result($id,$template){
      //Change the textfield's value into $id
      myid_some_function(); //Call another function
}


How will I do that?
I suggest you instead of creating link and try to call ajax with old method( call form your custom js file ) try  drupal ajax method

My suggestion is : 

function yourmodule_form_alter(&amp;$form,$form_state,$form_id){
if($form_id=='your specified form name '){
$form['id_number'] = array(
    '#title' =&gt; t('ID Number'),
    '#type' =&gt; 'textfield',  //textfield  
     '#prefix' =&gt; '&lt;div id="vm-container"&gt;',    
    '#suffix' =&gt; '&lt;/div&gt;'
    '#attributes' =&gt; array('id' =&gt; 'myid_search_id_number'),
 );
$form['myajax'] = array(
        '#type' =&gt;'button',
        '#value' =&gt; t('fill me'),
        '#ajax' =&gt; array(
            'callback' =&gt; '_myfuction_fill_number_ajax',
            'wrapper' =&gt; 'vm-container',
            'method' =&gt; 'replace',
            'effect' =&gt; 'fade',
            'prevent'=&gt; 'sumbmit',
        ),
    );
 }
}
function _myfuction_fill_number_ajax(&amp;$form,$form_state){
     $form['id_number'] ['#default_value'] = myid_some_function(); 
    // if not work try it with  $form['id_number'] ['#value'] = myid_some_function(); 
      return $form;
    }


also if you can want do ajax with jquery, add js file to your form, in that js file  set click handler for your link (  tag) and in click  call $.ajax with you menu rout.