Onchange 显示输入字段中的值不正确
Onchange show incorrect the value in the input fields
我在使 onchange 函数获取正确值时遇到问题。如果我 select 该选项,我想在 8 个输入字段中显示值。下面是我的 select 函数编码:
<select onchange="getComboA(this)" class="form-control blank" id="parentid" name="parentid" title="parentid">
<option>Please Select</option>
<option value="New Category_value"
data-function-code="' . $rs_incharge['function_code'] . '"
data-function-name="' . $rs_incharge['function_name'] . '"
data-activity-code="' . $rs_incharge['activity_code'] . '"
data-activity-name="' . $rs_incharge['activity_name'] . '"
data-sub-activity-code="' . $rs_incharge['sub_activity_code'] . '"
data-sub-activity-name="' . $rs_incharge['sub_activity_name'] . '"
data-transaction-code="' . $rs_incharge['transaction_code'] . '"
data-transaction-name="' . $rs_incharge['transaction_name'] . '"> New Category
</option>
<?php
$sql_incharge = 'select * from filing_code_management where status=1 order by id';
$arr_incharge = db_conn_select($sql_incharge);
foreach ($arr_incharge as $rs_incharge) {
$folder_location = $rs_incharge['folder_location'];
$function_code_select = $rs_incharge['function_code'];
$function_name_select = $rs_incharge['function_name'];
$activity_code_select = $rs_incharge['activity_code'];
$activity_name_select = $rs_incharge['activity_name'];
$sub_activity_code_select = $rs_incharge['sub_activity_code'];
$sub_activity_name_select = $rs_incharge['sub_activity_name'];
$transaction_code_select = $rs_incharge['transaction_code'];
$transaction_name_select = $rs_incharge['transaction_name'];
echo '<option value="' . $rs_incharge['function_code'] . '">' . $rs_incharge['name'] . '</option>';
}
?>
</select>
Jquery函数:
<script>
function getComboA() {
var sel = document.getElementById('parentid');
var selected = sel.options[sel.selectedIndex];
var data = selected.getAttribute('data-function-code');
document.getElementById("function_code").value =data;
var data = selected.getAttribute('data-function-name');
document.getElementById("function_name").value =data;
var data = selected.getAttribute('data-activity-code');
document.getElementById("activity_code").value =data;
var data = selected.getAttribute('data-activity-name');
document.getElementById("activity_name").value =data;
var data = selected.getAttribute('data-sub-activity-code');
document.getElementById("sub_activity_code").value =data;
var data = selected.getAttribute('data-sub-activity-name');
document.getElementById("sub_activity_name").value =data;
var data = selected.getAttribute('data-transaction-code');
document.getElementById("transaction_code").value =data;
var data = selected.getAttribute('data-transaction-name');
document.getElementById("transaction_name").value =data;
}
</script>
下面是错误输出,它不能显示正确的值,只是显示我在 selected 类别时的变量名。如果我 select 其他 selection,它也无法显示值:
Select 类别
Select other name 没有显示的值
完整代码:https://pastebin.com/9vyvL0SG
希望有人能指导我如何显示正确的 8 个输入字段中的值。
我看不到你的 PHP 代码从哪里开始,试试这个:
<select onchange="getComboA(this)" class="form-control blank" id="parentid" name="parentid" title="parentid">
<option>Please Select</option>
<?php
$sql_incharge = 'select * from filing_code_management where status=1 order by id';
$arr_incharge = db_conn_select($sql_incharge);
foreach ($arr_incharge as $rs_incharge) {
$folder_location = $rs_incharge['folder_location'];
$function_code_select = $rs_incharge['function_code'];
echo '<option value="' . $rs_incharge['function_code'] . '">' . $rs_incharge['name'] . '</option>';
}
?>
<option value="New Category_value"
data-function-code="<?php echo $rs_incharge['function_code']; ?>"
data-function-name="<?php echo $rs_incharge['function_name']; ?>"
data-activity-code="<?php echo $rs_incharge['activity_code']; ?>"
data-activity-name="<?php echo $rs_incharge['activity_name']; ?>"
data-sub-activity-code="<?php echo $rs_incharge['sub_activity_code']; ?>"
data-sub-activity-name="<?php echo $rs_incharge['sub_activity_name']; ?>"
data-transaction-code="<?php echo $rs_incharge['transaction_code']; ?>"
data-transaction-name="<?php echo $rs_incharge['transaction_name']; ?>"> New Category
</option>
</select>
我假设 $rs_incharge['function_code']
已经在 <select onchange...
之前定义
下面的示例将起作用,因为我们定义 $variable
在 我们使用 echo
:
<?php
$variable = 'This is awesome!';
echo $variable;
?>
下面的示例将给出错误,因为我们定义了 $variable
AFTER echo
:
<?php
echo $variable;
$variable = 'This is awesome!';
?>
我在使 onchange 函数获取正确值时遇到问题。如果我 select 该选项,我想在 8 个输入字段中显示值。下面是我的 select 函数编码:
<select onchange="getComboA(this)" class="form-control blank" id="parentid" name="parentid" title="parentid">
<option>Please Select</option>
<option value="New Category_value"
data-function-code="' . $rs_incharge['function_code'] . '"
data-function-name="' . $rs_incharge['function_name'] . '"
data-activity-code="' . $rs_incharge['activity_code'] . '"
data-activity-name="' . $rs_incharge['activity_name'] . '"
data-sub-activity-code="' . $rs_incharge['sub_activity_code'] . '"
data-sub-activity-name="' . $rs_incharge['sub_activity_name'] . '"
data-transaction-code="' . $rs_incharge['transaction_code'] . '"
data-transaction-name="' . $rs_incharge['transaction_name'] . '"> New Category
</option>
<?php
$sql_incharge = 'select * from filing_code_management where status=1 order by id';
$arr_incharge = db_conn_select($sql_incharge);
foreach ($arr_incharge as $rs_incharge) {
$folder_location = $rs_incharge['folder_location'];
$function_code_select = $rs_incharge['function_code'];
$function_name_select = $rs_incharge['function_name'];
$activity_code_select = $rs_incharge['activity_code'];
$activity_name_select = $rs_incharge['activity_name'];
$sub_activity_code_select = $rs_incharge['sub_activity_code'];
$sub_activity_name_select = $rs_incharge['sub_activity_name'];
$transaction_code_select = $rs_incharge['transaction_code'];
$transaction_name_select = $rs_incharge['transaction_name'];
echo '<option value="' . $rs_incharge['function_code'] . '">' . $rs_incharge['name'] . '</option>';
}
?>
</select>
Jquery函数:
<script>
function getComboA() {
var sel = document.getElementById('parentid');
var selected = sel.options[sel.selectedIndex];
var data = selected.getAttribute('data-function-code');
document.getElementById("function_code").value =data;
var data = selected.getAttribute('data-function-name');
document.getElementById("function_name").value =data;
var data = selected.getAttribute('data-activity-code');
document.getElementById("activity_code").value =data;
var data = selected.getAttribute('data-activity-name');
document.getElementById("activity_name").value =data;
var data = selected.getAttribute('data-sub-activity-code');
document.getElementById("sub_activity_code").value =data;
var data = selected.getAttribute('data-sub-activity-name');
document.getElementById("sub_activity_name").value =data;
var data = selected.getAttribute('data-transaction-code');
document.getElementById("transaction_code").value =data;
var data = selected.getAttribute('data-transaction-name');
document.getElementById("transaction_name").value =data;
}
</script>
下面是错误输出,它不能显示正确的值,只是显示我在 selected 类别时的变量名。如果我 select 其他 selection,它也无法显示值:
Select 类别
Select other name 没有显示的值
完整代码:https://pastebin.com/9vyvL0SG
希望有人能指导我如何显示正确的 8 个输入字段中的值。
我看不到你的 PHP 代码从哪里开始,试试这个:
<select onchange="getComboA(this)" class="form-control blank" id="parentid" name="parentid" title="parentid">
<option>Please Select</option>
<?php
$sql_incharge = 'select * from filing_code_management where status=1 order by id';
$arr_incharge = db_conn_select($sql_incharge);
foreach ($arr_incharge as $rs_incharge) {
$folder_location = $rs_incharge['folder_location'];
$function_code_select = $rs_incharge['function_code'];
echo '<option value="' . $rs_incharge['function_code'] . '">' . $rs_incharge['name'] . '</option>';
}
?>
<option value="New Category_value"
data-function-code="<?php echo $rs_incharge['function_code']; ?>"
data-function-name="<?php echo $rs_incharge['function_name']; ?>"
data-activity-code="<?php echo $rs_incharge['activity_code']; ?>"
data-activity-name="<?php echo $rs_incharge['activity_name']; ?>"
data-sub-activity-code="<?php echo $rs_incharge['sub_activity_code']; ?>"
data-sub-activity-name="<?php echo $rs_incharge['sub_activity_name']; ?>"
data-transaction-code="<?php echo $rs_incharge['transaction_code']; ?>"
data-transaction-name="<?php echo $rs_incharge['transaction_name']; ?>"> New Category
</option>
</select>
我假设 $rs_incharge['function_code']
已经在 <select onchange...
下面的示例将起作用,因为我们定义 $variable
在 我们使用 echo
:
<?php
$variable = 'This is awesome!';
echo $variable;
?>
下面的示例将给出错误,因为我们定义了 $variable
AFTER echo
:
<?php
echo $variable;
$variable = 'This is awesome!';
?>