一、首先我把这个输入框的代码贴出来
- <INPUT class="input-text f-input"onblur="changePrice(document.getElementById('goods_number_{$goods.rec_id}').value,{$goods.rec_id})" name="goods_number[{$goods.rec_id}]" id="goods_number_{$goods.rec_id}" value="{$goods.goods_number}"id="ECS_FORMBUY">
二、次 页面加入的javascript 也就是changeprice函数
- <script>
- /**
- * 点选可选属性或改变数量时修改商品价格的函数
- */
- function changePrice(number,rec_id)
- {
- //v//ar attr = getSelectedAttributes(document.forms['ECS_FORMBUY']);
- // var qty = document.forms['ECS_FORMBUY'].elements['number'].value;
- Ajax.call('flow.PHP','step=update_group_cart&rec_id=' + rec_id +'&number=' + number,changePriceResponse,'GET','JSON');
- }
- /**
- * 接收返回的信息
- */
- function changePriceResponse(res)
- {
- if (res.error > 0)
- {
- document.getElementById('sysmsg_error').innerHTML = res.content;
- document.all.sysmsg_error.style.display='';
- }
- else
- {
- if(document.all.sysmsg_error.style.display=='')
- {
- document.all.sysmsg_error.style.display='none';
- }
- document.getElementById('subtotal_'+res.rec_id).innerHTML = res.subtotal;//商品总价
- document.getElementById('cart_amount').innerHTML = res.cart_amount;//购物车团购商品价
- }
- }
- </script>
- <script>
- /**
- * 点选可选属性或改变数量时修改商品价格的函数
- */
- function changePrice(number,'JSON');
- }
- /**
- * 接收返回的信息
- */
- function changePriceResponse(res)
- {
- if (res.error > 0)
- {
- document.getElementById('sysmsg_error').innerHTML = res.content;
- document.all.sysmsg_error.style.display='';
- }
- else
- {
- if(document.all.sysmsg_error.style.display=='')
- {
- document.all.sysmsg_error.style.display='none';
- }
- document.getElementById('subtotal_'+res.rec_id).innerHTML = res.subtotal;//商品总价
- document.getElementById('cart_amount').innerHTML = res.cart_amount;//购物车团购商品价
- }
- }
- </script>
然后我把请求的PHP处理 程序也贴出来
- elseif($_REQUEST['step'] == 'update_group_cart')
- {
- /*------------------------------------------------------ */
- //-- 西安PHP服务中心团购更新购物车
- /*------------------------------------------------------ */
- include_once('includes/cls_json.PHP');
- $json = new JSON();
- $result = array('error' => '','content' => '');
- $rec_id = $_GET['rec_id'];
- $number = $_GET['number'];
- /*取的团购信息*/
- $group_buy = group_buy_info($_SESSION['extension_id'],$number);
- /*判断输入是否合法*/
- if(!is_numeric($number))
- {
- $result['error'] = '1';
- $result['content'] ='请输入合法数量';
- die($json->encode($result));
- }
- if ($group_buy['restrict_amount'] > 0 && $number > ($group_buy['restrict_amount'] - $group_buy['valid_goods']))
- {
- $result['error'] = '1';
- $restrict_amount =$group_buy['restrict_amount'] - $group_buy['valid_goods'];
- $result['content'] ='您最多可买'.$restrict_amount.'件';
- die($json->encode($result));
- }
- $sql = "UPDATE " . $GLOBALS['ecs']->table('cart') . " SET goods_number = '$number' WHERE rec_id = $rec_id";
- $GLOBALS['db']->query($sql);
- /*计算此订单总价*/
- $subtotal = $GLOBALS['db']->getONE("select goods_price * goods_number AS subtotal from ".$GLOBALS['ecs']->table('cart')." where rec_id = $rec_id");
- /*购物车团购商品总金额*/
- $cart_amount = cart_amount('',$_SESSION['flow_type']);
- $result['subtotal'] = price_format($subtotal,false);
- $result['cart_amount'] = price_format($cart_amount,false);
- $result['rec_id'] = $rec_id;
- die($json->encode($result));
- }