doubeiji2602 2014-08-12 13:31
浏览 18
已采纳

PHP如果在表单输入中

I want the $delivery in the top input to change value depending on the value on another variable I'm using.

I'm just not sure how to place another if inside the current if and how to match up the value="0.00" so it all works together

<form action="" method="post" onclick="this.submit()">
    <input <?php if ($delivery=='0.00'){ echo 'checked="checked"';} ?> type="radio" value="0.00" name="delivery">&nbsp; Economy - up to 4 working days<br>
    <input <?php if ($delivery=='4.99'){ echo 'checked="checked"';} ?> type="radio" value="4.99" name="delivery">&nbsp; Express - next day <br>
    <input <?php if ($delivery=='9.99'){ echo 'checked="checked"';} ?> type="radio" value="9.99" name="delivery">&nbsp; Saturday<br>
</form>

Thanks.

What i ended up doing was this:

if ($pricetotal <= 50.00) {
$amount1 = 3.99;
}
elseif ($pricetotal >= 50.01) {
$amount1 = 0.00;
}

Then in my form changing it to this:

<form action="" method="post" onclick="this.submit()">
<input <?php if ($delivery<='3.99'){ echo 'checked="checked"';} ?> type="radio" value="       <?php echo htmlspecialchars($amount1); ?>" name="delivery">&nbsp; Economy - up to 4 working days<br>
<input <?php if ($delivery=='4.99'){ echo 'checked="checked"';} ?> type="radio" value="4.99" name="delivery">&nbsp; Express - next day <br>
<input <?php if ($delivery=='9.99'){ echo 'checked="checked"';} ?> type="radio" value="9.99" name="delivery">&nbsp; Saturday<br>

I might not have explained exactly what i needed as i thought there would be a simple fix, but i wanted the top inputs value do change depending on $pricetotal and i managed to get it working.

Thanks for the help.

  • 写回答

2条回答 默认 最新

  • dongqiao3214 2014-08-12 13:43
    关注

    I would do something like this:

    $deliveryEconomy = '';
    $deliveryExpress = '';
    $deliverySaturday = '';
    
    switch($delivery)
    {
       case 0.00:
       $deliveryEconomy = 'checked="checked"';
       break;
    
       case 4.99:
       $deliveryExpress = 'checked="checked"';
       break;
    
       case 9.99:
       $deliverySaturday = 'checked="checked"';
       break;
    }
    
    <form action="" method="post" onclick="this.submit()">
    <?php 
    echo "<input $deliveryEcononomy type='radio' value='0.00' name='delivery'>&nbsp; Economy - up to 4 working days<br>";
    echo "<input $deliveryExpress type='radio' value='4.99' name='delivery'>&nbsp; Express - next day <br>";
    echo "<input $deliverySaturday type='radio' value='9.99' name='delivery'>&nbsp; Saturday<br>";
    ?>
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答