ONCHANGE HO值问题
Onchange echo value probelm
我在创建 select 框然后获取要在其他输入字段中显示的值时遇到问题。
下面是我试过的代码:
<div class="form-group">
<label for="cp1" class="control-label col-lg-4">Move to Sub Folder/New Category<span style="color:red;"> *</span></label>
<div class="col-lg-3">
<select class="form-control blank" id="parentid" name="parentid" title="parentid">
<option>Please Select</option>
<option value="0">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'];
echo '<option value="' . $rs_incharge['category_id'] . '">' . $rs_incharge['name'] . '</option>';
}
?>
</select>
<!--<input type="text" class="form-control blank" id="parentid" name="parentid" title="parentid" onblur="capitalize(this.id, this.value);">-->
</div>
</div>
<div class="form-group">
<label for="cp1" class="control-label col-lg-4">Function Code:</label>
<div class="col-lg-3">
<input type="text" class="form-control" id="function_code" name="function_code" title="function_code" value="<?php echo $function_code_select;?>">
</div>
</div>
我定义了$function_code_select = $rs_incharge['function_code'];因为我需要在第二个输入字段中获取功能代码编号,所以我在第二个输入字段中写了 echo $function_code_select;显示价值,但它不起作用。希望有人能指导我如何解决它。谢谢
下面是我需要显示输出的示例。如果可行,它可以告诉我更正第二个输入字段中的 function_code:
您不能使用 PHP 执行此操作,它是服务器端脚本语言。
添加一些 javascript 让奇迹发生:
<div class="form-group">
<label for="cp1" class="control-label col-lg-4">Move to Sub Folder/New Category<span style="color:red;"> *</span></label>
<div class="col-lg-3">
<select onchange="getComboA(this)" class="form-control blank" id="parentid" name="parentid" title="parentid">
<option>Please Select</option>
<option value="New Category_value">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'];
echo '<option value="' . $rs_incharge['category_id'] . '">' . $rs_incharge['name'] . '</option>';
}
?>
</select>
<!--<input type="text" class="form-control blank" id="parentid" name="parentid" title="parentid" onblur="capitalize(this.id, this.value);">-->
</div>
</div>
<div class="form-group">
<label for="cp1" class="control-label col-lg-4">Function Code:</label>
<div class="col-lg-3">
<input type="text" class="form-control" id="function_code" name="function_code" title="function_code" value="<?php echo $function_code_select;?>">
</div>
</div>
<script>
function getComboA(selectObject) {
var value = selectObject.value;
document.getElementById("function_code").value =value;
}
</script>
如果您需要保留 value=""
,您可以添加一个额外的属性,例如 data-function-code=""
<div class="form-group">
<label for="cp1" class="control-label col-lg-4">Move to Sub Folder/New Category<span style="color:red;"> *</span></label>
<div class="col-lg-3">
<select onchange="getComboA()"
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'] . '">
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'];
echo '<option value="' . $rs_incharge['category_id'] . '">' . $rs_incharge['name'] . '</option>';
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="cp1"
class="control-label col-lg-4">Function Code:</label>
<div class="col-lg-3">
<input type="text"
class="form-control"
id="function_code"
name="function_code"
title="function_code"
value="<?php echo $function_code_select;?>">
</div>
</div>
<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;
}
</script>
我在创建 select 框然后获取要在其他输入字段中显示的值时遇到问题。
下面是我试过的代码:
<div class="form-group">
<label for="cp1" class="control-label col-lg-4">Move to Sub Folder/New Category<span style="color:red;"> *</span></label>
<div class="col-lg-3">
<select class="form-control blank" id="parentid" name="parentid" title="parentid">
<option>Please Select</option>
<option value="0">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'];
echo '<option value="' . $rs_incharge['category_id'] . '">' . $rs_incharge['name'] . '</option>';
}
?>
</select>
<!--<input type="text" class="form-control blank" id="parentid" name="parentid" title="parentid" onblur="capitalize(this.id, this.value);">-->
</div>
</div>
<div class="form-group">
<label for="cp1" class="control-label col-lg-4">Function Code:</label>
<div class="col-lg-3">
<input type="text" class="form-control" id="function_code" name="function_code" title="function_code" value="<?php echo $function_code_select;?>">
</div>
</div>
我定义了$function_code_select = $rs_incharge['function_code'];因为我需要在第二个输入字段中获取功能代码编号,所以我在第二个输入字段中写了 echo $function_code_select;显示价值,但它不起作用。希望有人能指导我如何解决它。谢谢
下面是我需要显示输出的示例。如果可行,它可以告诉我更正第二个输入字段中的 function_code:
您不能使用 PHP 执行此操作,它是服务器端脚本语言。 添加一些 javascript 让奇迹发生:
<div class="form-group">
<label for="cp1" class="control-label col-lg-4">Move to Sub Folder/New Category<span style="color:red;"> *</span></label>
<div class="col-lg-3">
<select onchange="getComboA(this)" class="form-control blank" id="parentid" name="parentid" title="parentid">
<option>Please Select</option>
<option value="New Category_value">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'];
echo '<option value="' . $rs_incharge['category_id'] . '">' . $rs_incharge['name'] . '</option>';
}
?>
</select>
<!--<input type="text" class="form-control blank" id="parentid" name="parentid" title="parentid" onblur="capitalize(this.id, this.value);">-->
</div>
</div>
<div class="form-group">
<label for="cp1" class="control-label col-lg-4">Function Code:</label>
<div class="col-lg-3">
<input type="text" class="form-control" id="function_code" name="function_code" title="function_code" value="<?php echo $function_code_select;?>">
</div>
</div>
<script>
function getComboA(selectObject) {
var value = selectObject.value;
document.getElementById("function_code").value =value;
}
</script>
如果您需要保留 value=""
,您可以添加一个额外的属性,例如 data-function-code=""
<div class="form-group">
<label for="cp1" class="control-label col-lg-4">Move to Sub Folder/New Category<span style="color:red;"> *</span></label>
<div class="col-lg-3">
<select onchange="getComboA()"
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'] . '">
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'];
echo '<option value="' . $rs_incharge['category_id'] . '">' . $rs_incharge['name'] . '</option>';
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="cp1"
class="control-label col-lg-4">Function Code:</label>
<div class="col-lg-3">
<input type="text"
class="form-control"
id="function_code"
name="function_code"
title="function_code"
value="<?php echo $function_code_select;?>">
</div>
</div>
<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;
}
</script>