douyinglan2599 2013-01-30 18:44
浏览 36
已采纳

将Javascript变量显示为PHP变量

In my form action there's a url: www.url.com/?quantity=$quantity

And in the form there's a select box where customers choose the quantity.

<form method="post" name="jform" action="www.url.com/?quantity=$quantity">
<select class="font_12" id="quantity" name="quantity">
    <option value="10">10 PCs</option>
    <option value="25">25 PCs</option>
    <option value="50">50 PCs</option>
    <option value="99">99 PCs</option>
</select>

I am trying to get the value in the select box using ajax, and then display into the action form url. I did a alert and it works, I am getting the value of the select box. But I don't know how to put this vaue into the PHP varaible $quantity?

Here's my Ajax code:

$('#quantity').on('change', function() {
var val = $(this).val();
if(val != '') {
    $.get('index.php', {'quantity' : val}, function(resp) {
        alert(val);
    });
}
});

Actually I want it to change the php variable right away when the quantity in the select box change before submitting the form.

Any help?

  • 写回答

1条回答 默认 最新

  • dsyua2828 2013-01-30 18:46
    关注

    Use $_GET

    If your URL is ?quantity=### then just use $_GET['quantity'] in your PHP code.

    To change the action attribute on the form when you change the quantity you can just put the following inside your onchange event:

    $('form[name="jform"]').attr('action','http://url.com/?quantity=' + val);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算