我有一个问题是根据用户在另一个输入字段中输入的值在输入字段中显示查询结果。这是动态输入字段(用户可以使用javascript添加或删除行)。这是我的代码:
<script language="javascript" type="text/javascript">
/*
Javascript Multi Field Dynamic Generator
*/
var ct = 1;
// Function Tambah Form
function new_link()
{
ct++;
var div1 = document.createElement('div');
div1.id = ct;
// Link to Delete Form
var delLink = '<div style="text-align:left"><a id="del" href="javascript:delIt('+ ct +')">Delete</a></div>';
div1.innerHTML = document.getElementById('newlinktpl').innerHTML + delLink;
document.getElementById('newlink').appendChild(div1);
}
// Function Delete Form
function delIt(eleId)
{
d = document;
var ele = d.getElementById(eleId);
var parentEle = d.getElementById('newlink');
parentEle.removeChild(ele);
}
</script>
<a id="new" href="javascript:new_link()">ADD NEW PAYMENT </a>
<div id="newlink">
<table id="fit" width="90%">
<tr bgcolor="#E0ECFF">
<th>Type</th>
<th>IDNO</th>
<th>Bank</th>
<th>Ket</th>
<th>text</th>
<th>text</th>
<th>option</th>
<th align="right">Amount</th>
</tr>
<tr>
<td>
<select name="type[]">
<?php
$sql_paytype = mssql_query("...");
while($rp = mssql_fetch_array($sql_paytype)){
?>
<option value="<?php echo "$rp[Kd_Pay]#$rp[RepCd]";?>"><?php echo $rp[Nm_Pay]?></option>
<?php
}
?>
</select>
</td>
<td>
// USER ENTER PARAMETER VALUE IDNO TO SELECT AMOUNT FROM TABLE WHERE IDNO = $IDNO
<input style="width:80px;" type="text" name="idno[]" />
</td>
<td>
<select name="bank[]">
<option value=""></option>
<?php
$sql_bank = mssql_query("SELECT ...");
while($rb = mssql_fetch_array($sql_bank)){
?>
<option value="<?php echo $rb[Kd_Bank]?>"><?php echo "$rb[Kd_Bank] - $rb[Nm_Bank]";?></option>
<?php
}
?>
</select>
</td>
<td>
<input style="width:90px;" type="text" name="ket[]" />
</td>
<td><input style="width:90px;" type="text" name="text[]" /></td>
<td><input style="width:100px;" type="text" name="text[]" /></td>
<td>
<select name="option[]">
<?php
$sql_curr = mssql_query("SELECT ...");
while($rc = mssql_fetch_array($sql_curr)){
?>
<option value="<?php echo "$rc[KD_CURR]#$rc[KODE]";?>"><?php echo "$rc[KODE]";?></option>
<?php
}
?>
</select>
</td>
<td>
// AND THEN QUERY RESULT AMOUNT WILL BE DISPLAYED IN THIS INPUT FIELD
<input style="text-align:right" type="text" name="amount[]" value="<?php echo $msg?>" onKeyUp="formatNumber(this)" />
</td>
</tr>
</table>
</div>
<br/>
<input type="submit" name="submit" value="Save" /> <input type="reset" name="reset" value="Reset" />
</form>
</fieldset>
</div>
</fieldset>
<!-- Template For Dynamic Multiple Field -->
<div id="newlinktpl" style="display:none" >
<div>
<table id="fit" width="90%">
<tr>
<td>
<select name="type[]">
<?php
$sql_paytype = mssql_query("...");
while($rp = mssql_fetch_array($sql_paytype)){
?>
<option value="<?php echo "$rp[Kd_Pay]#$rp[RepCd]";?>"><?php echo $rp[Nm_Pay]?></option>
<?php
}
?>
</select>
</td>
<td>
<input style="width:80px;" type="text" name="idno[]" />
</td>
<td>
<select name="bank[]">
<option value=""></option>
<?php
$sql_bank = mssql_query("...");
while($rb = mssql_fetch_array($sql_bank)){
?>
<option value="<?php echo $rb[Kd_Bank]?>"><?php echo "$rb[Kd_Bank] - $rb[Nm_Bank]";?></option>
<?php
}
?>
</select>
</td>
<td>
<input style="width:90px;" type="text" name="ket[]" />
</td>
<td><input style="width:90px;" type="text" name="text[]" /></td>
<td><input style="width:100px;" type="text" name="text[]" /></td>
<td>
<select name="option[]">
<?php
$sql_curr = mssql_query("...");
while($rc = mssql_fetch_array($sql_curr)){
?>
<option value="<?php echo "$rc[KD_CURR]#$rc[KODE]";?>"><?php echo "$rc[KODE]";?></option>
<?php
}
?>
</select>
</td>
<td>
<input style="text-align:right" type="text" name="amount[]" value="" onKeyUp="formatNumber(this)" />
</td>
</tr>
</table>
</div>
</div>
所以,基本上我希望输入字段(名称数量[])将根据用户输入的输入字段(idno [])值显示查询结果 .. 请帮我实现这个目标..
非常感谢答案 0 :(得分:0)
您需要在用户退出字段idno后添加ajax调用。此ajax调用应将idn值发送到服务器,然后您的服务器将能够查询您的数据库并返回您的金额字段所需的值
答案 1 :(得分:0)
你必须在某些javascript变量中获取idno []值或使用jquery $("#idno").val()
使用以下命令发送此值:
$.ajax({
type:'post',
url:"you php call",
data: $("#idno").val(),
success : function(data) {// here data is what ever you are returning from method.
// show this received data to your page without page refresh.
}
});