[英]How to display value in text box according to the value which is selected in the drop down box?
[英]How to get value to text box according to selected value with reference to database in php?
以下是我的数据库值
+----+--------------------+-------------+
| id | type | rate |
+----+--------------------+-------------+
| 1 | Accord|Corola|Tata | Out|Loc|Out |
+----+--------------------+-------------+
我展开了type
列的值,并成功地在view
页面的select tag
中显示了它。
我有另一个textbox
,我需要根据选择的type
位置显示rate
。
<input type="text" id="rate">
当我们选择dropdown
type
值时,如何在textbox
获取所需的值?
我正在使用Code Igniter框架。
提前致谢...
仅将select tag中的值存储值作为下面给出的值。
<select id="type_select">
<option value="Out">Accord</option>
<option value="Loc">Corola</option>
<option value="Out">Tata</option>
</select>
在jquery中select
onchange获取速率值并显示它。
Javascript代码:
$( "#type_select" ).change(function() {
var rate = $( "#type_select option:selected" ).val();
$("#rate").val(rate);
});
$types=explolde("|",$type);
$rates=explolde("|",$rate);
$dataArray = array();
$i = 0;
foreach($types as $value){
$dataArray[$value] = $rates[$i++]; // I assume size of both array is same,
//you may check additional exception handling.
}
$dataArray
具有实际值,根据您的要求从此数组中获取值,因为您现在有了地图。
你可以尝试在选择的javascript中添加选择事件,并通过ajax加载相应的速率。
添加类似的事件
$(document).on("change","#type",function(e){
var type=$(this).find("option:selected").val();
//load ajax call
jQuery.ajax({
type: mtdf, // HTTP method POST or GET
url: url, //Where to make Ajax calls
dataType: "json", // Data tr_, HTML, json etc.
data:{type:type}, //data to the server,
success: function (response) {
//console.log(response);
},
error: function (xhr, ajaxOptions, thrownError){
}
});
});
试试
<?php
$type = 'Accord|Corola|Tat';
$rate = 'Out|Loc|Out';
$new_type = explode('|',$type);
$new_rate = explode('|',$rate);
echo "<select onchange='getValue()' id='theSelect'>";
for($x=0;$x<count($new_rate);$x++){
echo "<option value = '".$new_rate[$x]."' > ".$new_type[$x]." </option>";
}
echo "</select>";
?>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
function getValue(){
var valSelect = $("#theSelect").val();
$("#rate").val(valSelect);
}
</script>
<input type="text" id="rate">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.