duandi1636 2009-06-11 12:19
浏览 80

如何将变量从JavaScript传递给PHP?

I am using jQuery to calculate prices. Here is a small snippet of my JavaScript:

// Prices: radio
var curLam = "gloss";
$("input[name=lamination]").click(function(){
    var gloss = 5;
    var matt = 6;
    if ($(this).val() == 'gloss' && curLam != 'gloss'){
        $('#prices span').text(parseInt($('#prices span').text()) + gloss - matt);
        curLam = 'gloss';
        console.log('1');
    }
    if ($(this).val() == 'matt' && curLam != 'matt'){
        $('#prices span').text(parseInt($('#prices span').text()) - gloss + matt);
        curLam = 'matt';
        console.log('2');
    }
        $("#prices span").each(function(){
var $priceValue = $(this);
    } )

});

This checks to see if a matte or gloss finish has been selected and then it inserts the price into the span within the prices div tag.

I need to know how to assign that price value into a variable which can then be passed on to PHP for my shopping cart.

  • 写回答

2条回答 默认 最新

  • doucanshou6998 2009-06-11 12:21
    关注

    You could put the ID of the product into an input element and then when you submit into the shopping cart, then the value should be in your php $_POST variables.

    There you can check the price and other information straight from your database.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害