drjmrg8766 2016-07-06 03:03
浏览 144
已采纳

PHP使用id属性获取表单数据

I'm making a form with checkboxes and radiobuttons I use the value as price, which I calculate with a script so I get the total price of the selected checkboxes and radiobuttons.

<script>
function calcscore() {
    score = 0;
    $(".calc:checked").each(function () {
        score += Number($(this).val());
    });
    $("#price").text(score.toFixed(2));
    $("#sum").val(score)
}
$().ready(function () {
    $(".calc").change(function () {
        calcscore()
    });
});
</script>

<input type="radio" id="1" value="40" class= "calc" name = "780143050"> Gezichtsbehandeling (incl.)<br>
<input type="radio" id="2" value="40" class = "calc" name = "780143050"> Massage<br>
<input type="radio" id="3" value="75" class = "calc" name = "780143050"> beide 
<span id="output"></span><input type="hidden" name="sum" id="sum" value="0">
                <p>Totaal extra's : €  <span id="price">0</span>

I have the following PHP

test.php

<?php
   echo("keuze : " . $_POST['780143050'] . "<br />
");
?>

I in my php script the value and the ID. How can I echo the ID of the selected radiobutton?

  • 写回答

2条回答 默认 最新

  • douquqiang1513 2016-07-06 04:10
    关注

    There are 2 ways to do this:

    1. change the value of value to the value of the id
    2. add the value of the id to the value

    html:

    <input type="radio" id="2" value="40|2" class = "calc" name = "780143050"> Massage<br>
    

    js:

    <script>
    function calcscore() {
        score = 0;
        $(".calc:checked").each(function () {
            score += Number($(this).val().split('|')[0]);
        });
        $("#price").text(score.toFixed(2));
        $("#sum").val(score)
    }
    $().ready(function () {
        $(".calc").change(function () {
            calcscore()
        });
    });
    

    php

    <?php
       echo("keuze : " . split('|',$_POST['780143050'])[1] . "<br />
    ");
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?