-2
我使用PHP和Postgres數據庫。我想要一個表值填充在文本框中輸入特定值(做了一定的計算後)..我試圖使用onchange事件,然後調用一個Ajax函數,但它不工作..我使用兩個AJAX函數..將工作?文本框上的變化,ajax函數被稱爲...不工作
的Ajax功能:
function getAmount(order_quant,item)
{
var strURL = "calc_amt.php?order=" + order_quant + "&item=" + item;
var req = getXMLHTTP();
if (req)
{
req.onreadystatechange = function()
{
if (req.readyState == 4)
{
// only if "OK"
if (req.status == 200)
{
document.getElementById('amt').innerHTML = req.responseText;
}
else
{
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
HTML:
<tr>
<td>
<?php echo $articles['item_name']; ?>
</td>
<td>
<?php echo $tot."(".$articles['description'].")";?>
</td>
<td>
<?php echo $articles['qty_in_stock'];?>
</td>
<td>
<?php echo $articles['min_reorder_qty'];?>
</td>
<td>
<input type="text" name="ordered_quant" id="order_quant" onChange="getAmount(this.id,$value)" required/>
</td>
<td>
<div id="amt"></div>
</td>
<td>
<?php echo $order_date; ?>
</td>
</tr>
纔能有代碼嗎? –
Ajax的功能:功能getAmount(order_quant,項目){\t \t \t \t \t VAR \t strURL = 「?calc_amt.php順序=」 + order_quant + 「&項=」 +項; \t \t var req = getXMLHTTP(); \t \t \t 如果\t(REQ){ \t \t \t \t \t \t req.onreadystatechange =函數(){ \t \t \t \t如果(req.readyState == 4){ \t \t \t \t \t //僅當「OK」時 \t \t \t \t \t if(req.stat我們== 200){\t \t \t \t \t \t \t \t \t \t \t \t的document.getElementById( 'AMT')的innerHTML = req.responseText。 \t \t \t \t \t \t \t \t \t \t \t}否則{ \t \t \t \t \t \t警報( 「有同時使用XMLHTTP是一個問題:\ n」 個+ req.statusText); \t \t \t \t \t} \t \t \t \t \t} \t \t \t \t \t \t \t} \t \t \t \t \t req.open( 「GET」,strURL,TRUE); \t \t \t req。發送(NULL); \t \t \t} \t \t } – Sharvari
HTML代碼:?
回答
你的問題是第二個參數。你在那裏混合使用PHP和Javascript。 確保你(PHP)標記您的代碼
我假設$值是一個PHP變量有...
來源
2012-11-30 06:50:02 Manatax
謝謝!它稱爲函數,但它沒有給出在文本框中輸入的值 – Sharvari
謝謝我明白了......它的工作原理...... !!! – Sharvari
一個很高興在服務;) – Manatax
相關問題