0

有没有办法从下拉列表或收音机中自动检索选定的值以形成下面的形式?下图中的示例,如果我选择单选按钮“randy”,则值“randy”会自动填写下面的表格 Nama

在此处输入图像描述

$header1 = array('Name'); // Prepare table header
$query = db_select("homo", "r"); // Select table  
$query->fields("r", array("nama")); // Select fields    
$result = $query->execute(); // Execute query 
$rows = array();
while($data = $result->fetchObject()){ // Looping for filling the table rows  
$rows[] = array( // Fill the table rows
  $data->nama,
  );
}
$form['table'] = array (
 '#type' => 'tableselect',
 '#header' => $header1,
 '#options' => $rows,
 '#multiple' => FALSE,  
);
$form['f1'] = array(
 '#title' => t('Detail Anggota'),
 '#type' => 'fieldset',    
);
$form['f1']['namaa'] = array(
 '#title' => t('Nama'),
 '#type' => 'textfield',    
 '#required' => TRUE,
);
4

2 回答 2

0

您可以使用 javascript 为您执行此操作。类似下面的代码可以轻松完成您的任务。

<script type="text/javascript">
//<![CDATA[
    $(document).ready(function(){
         var checkbox = document.getElementsByName('checkbox_type');
         for(var i = 0; i < checkbox.length; i++) {
             if(checkbox[i].checked == true) {
                  $('input[name=namaa]').val($(checkbox[i]).text());
             }
         }
    });
//]]>
</script>
于 2013-06-18T10:32:15.977 回答
0

你也可以像这样从你的 HOOK_form_alter 添加 JS:

$form['#attached']['js'][] = drupal_get_path('module', 'mymodulename') . '/js/myjsname.js';
于 2013-06-28T16:00:46.243 回答