php - 没有提交的单选按钮值到mysql

标签 php javascript jquery mysql ajax

我绝不是 javascript 程序员,所以如果有人能帮助我解决这个问题就太好了。如果在同一页面上有多个这样的评级部分,如下面的示例所示。

现在我需要将已单击的单选按钮的值发送到我的数据库,而不需要提交按钮,最好不要刷新。

<body>
    <section class="rating">
        <input type="radio" class="radio twenty" name="progress" value="twenty" id="twenty" <?php if($num === 1) { echo 'checked'; } ?>>
        <label for="twenty" class="label">1</label>

        <input type="radio" class="radio fourty" name="progress" value="fourty" id="fourty" <?php if($num === 2) { echo 'checked'; } ?>>
        <label for="fourty" class="label">2</label>

        <input type="radio" class="radio sixty" name="progress" value="sixty" id="sixty" <?php if($num === 3) { echo 'checked'; } ?>>
        <label for="sixty" class="label">3</label>

        <input type="radio" class="radio eighty" name="progress" value="eighty" id="eighty"<?php if($num === 4) { echo 'checked'; } ?>>
        <label for="eighty" class="label">4</label>

        <input type="radio" class="radio onehundred" name="progress" value="onehundred" id="onehundred" <?php if($num === 5) { echo 'checked'; } ?>>
        <label for="onehundred" class="label">5</label>

        <div class="progress">
            <div class="progress-bar"></div>
        </div>
    </section>
</body>

我已经设置了检索选中的单选按钮,使其对应于 1 到 5 的评级,所以我目前正在使用测试数据来显示 1 到 5 的评级。

我不一定需要所有的细节,需要完成的步骤的概述已经非常有帮助了。

最佳答案

应该这样做

DEMO

在jQuery include之后添加到头部 而且我把class改成了进度条的id

$(function() { // when document has loaded
  $(".radio").on("click",function() { // all radios with class="radio ..." 
    // ajax get or post someserver.php?value=twenty/fourty...
    $.get("someserver.php", {value:this.value},function(data) { 
      // add the returned value to a container
      $("#progress-bar").append("Updated "+ data); 
    });
  });
});

关于php - 没有提交的单选按钮值到mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16277078/

相关文章:

php - 如何在 yii2-localeurls 中禁用特定 Controller /模块的语言环境重定向

php - PDO 变量在查询中不起作用,但静态值有效

php - 使用 foreach 循环填充数组

javascript - 使用 Angular 通过 DOM 检查类是否存在

javascript - Highchart 中多个图表的快速切换

javascript - jQuery Ajax 单击调用仅有效一次

javascript - 如何在页面加载时使用 jQuery Address 插件加载当前内容?

php - 使用 php/mysql 更新密码

javascript - 带有 fnDisplayRow 的数据表

javascript - 动画文本向上滑动并使用 jquery 替换为另一个文本