我在填写表单字段时遇到问题。
当从第一行输入字段中的doropdown字段中选择值时,我有5个从数据库填充的字段。要使用以下方法获取这些值: “.select_ttl”是一个下拉名称属性。
$(".select_ttl").change(function(event){
var kit=$(".select_ttl").val();
$.getJSON('/getanimation.php?kit=' + kit, null,
function(data)
{
$("#kit").val(data.kit);
$("#animation").val(data.animation);
$("#prix").val(data.prix);
});
});
php文件是:
<?php
require_once("inc/init.php");
require_once("inc/session.php");
require_once('inc/sql.php');
require_once("inc/config.ui.php");
header('Content-Type: application/json');
$title = $_GET["kit"]; // we received this from the json call
$Mysql = new Mysql();
$array_action = $Mysql->TabResSQL("SELECT * FROM liste_animation inner join kit ON liste_animation.ID_LISTE_ANIMATION=kit.ID_LISTE_ANIMATION where kit.CODE='".$title."' ");
foreach($array_action as $key){
$data = array(
'kit' => $key->CODE,
'animation' => $key->NOM_ANIMATION,
'prix' => $key->PRIX_ANIMATEUR,
);
}
echo (json_encode($data));
?>
使用此代码我只获得一行的值,在表单中有一个选项可以添加一行新的输入字段。所以mu问题是如何为多行做同样的事情?提前谢谢。
这是表格示例:
<div class="form-inline col-xs-2">
<select class="select_ttl form-control" name="kit" id="kit">
<option class='select_ttl' value="" selected="selected" disabled="disabled">Kit</option>
<?php
$Mysql = new Mysql();
$ArraySelect = $Mysql->TabResSQL('SELECT distinct KIT from kit_voyage');
foreach($ArraySelect as $key){
echo "<option value=".$key->KIT.">".$key->KIT."</option>";
?>
<?php } ?>
</select> <!-- end .select_ttl -->
</div>
<!-- Text input-->
<div class="form-group col-xs-3">
<input id="animation" name="animation" type="text" placeholder="nom animation" class="input_fn form-control" required="" value=''>
</div>
<!-- Text input-->
<div class="form-group col-xs-2">
<input id="prix" name="prix" type="text" placeholder="PU_HT" class="input_ln form-control" value=''>
</div>
<!-- Text input-->
<div class="form-group col-xs-2">
<input value="1" id="quantity" name="quantity" type="text" placeholder="qtité" class="input_email form-control">
</div>
<div class="form-group col-xs-2">
<input id="tva" name="tva" type="text" placeholder="TVA" class="input_email form-control">
</div>
<div class="form-group col-xs-2">
<input id="rem" name="rem" type="text" placeholder="REM" class="input_email form-control">
</div>
<div class="form-group col-xs-2">
<input id="totaltt" name="totaltt" type="text" placeholder="Total TT" class="input_email form-control">
</div>
答案 0 :(得分:0)
使用
$(".select_ttl").change(function(event){
var kit=$(this).val();
});
&安培;而不是echo (json_encode($data));
使用echo json_encode($data);
删除外{{1p>