[英]change event of a radio button to get a value from mysql table, not working
jQuery(document).ready(function(){
$("#qty1").change(function(e) {
var quantity = $(this).val();
$.ajax({
url: 'pricegetter.php',
type: 'POST',
data: {quantity: quantity},
success: function(result) {
$('#price').val(result);
}
});
});
});
pricegetter.php的代码
include("config.php");
$q = mysql_query("select rate FROM products WHERE qty= '".$_POST['quantity']."'");
if(mysql_num_rows($q)<=0) echo "none";
else{
$r = mysql_fetch_array($q);
echo $r["rate"];
}
我的单选按钮触发事件
<input type='radio' value='".$row['qty']."' name='qty1' id='qty1'/> ".$row['qty'] ." ".$row['unit'] />
我的值要通过文本字段存储。
<input type='text' name='price' id='price'/>
上面的这些代码无法正常工作。 请帮助我找到错误。 我的php代码可以单独完美地工作,没有语法或字段名错误。
代码的目的是,当我选择一个qty1单选按钮时,它将为我提供与特定产品的数量相关的价格。 [ps我在代码的第一步。 我不知道如何使用jquery发送两个值作为后期操作,因此我只发送数量,但没有给我价格。 然后,我将尝试通过jquery提供productID。]
您可以使用逗号分隔值发送多个数据,例如在ajax中
data: {quantity: quantity,price:price},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.