0

enter image description here

Above is the sample screenshot of my form where I would like to do is:

When I click/check on radio button "One" then its value should display in textfield of "Display".

Code:

function test_radio_menu() {
  $items['test_radio'] = array(
    'title' => 'test_radio',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('test_radio_form'),
    'access arguments' => array('access content'),
    'access callback' => TRUE,
    );
  return $items;
}

/**
* Implements hook_form().
*/

function test_radio_form($form, &$form_submit){

/* the options to display in our form radio buttons */
$options = array(
  'one' => t('One'),
   'two' => t('Two'),
);

$form['count'] = array(
  '#title' => t('Count'),
  '#type' => 'radios',
  '#options' => $options,

);

$form['display'] = array(
'#title' => t('Display'),
'#type' => 'textfield',
'#value' => ,
  );

$form['submit'] = array(
'#value' => t('PROCEED'),
'#type' => 'submit',
  );

return $form;
}
0

2 Answers 2

1

You should use drupal ajax form try this code

function test_radio_form($form, &$form_submit){

/* the options to display in our form radio buttons */
$options = array(
  'one' => t('One'),
   'two' => t('Two'),
);

$form['count'] = array(
  '#title' => t('Count'),
  '#type' => 'radios',
  '#options' => $options,
  '#ajax' => array(
            'callback' => 'myid_print_all_submitted_id_callback',
            'wrapper' => 'myid_print_search_idnumber_wrapper',
  ),

);

$form['display'] = array(
'#title' => t('Display'),
'#type' => 'textfield',
'#value' => isset($form_state['values']['count']) ? $form_state['values']['count'] : '',
'#prefix' => '<div id="myid_print_search_idnumber_wrapper">',
'#suffix' => '</div>',
  );

$form['submit'] = array(
'#value' => t('PROCEED'),
'#type' => 'submit',
  );

return $form;
}
function myid_print_all_submitted_id_callback($form, $form_state)
{
      return $form['display'];
}
0

it should work like this

html :

  <input type="radio" name="mode" id="radio"   class="test1" value="text" onclick="BT('#message')" />

js

function BT (id) {

    $('.Bt')..attr('id', 'your-id-value');

}
3
  • hi madman thanks for your reply, but i want to make in drupal 7. Oct 5, 2014 at 22:40
  • its jquery you can add it to you template file and see the result its should not make problem . but if the page created by drupal you need to add js to header file then add html in your editor useing html code editor
    – madman
    Oct 6, 2014 at 12:01
  • -madman- thanks for your suggestion i will try it soon. Oct 6, 2014 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.