【问题标题】:Get checked radio button value dynamically in Laravel 8在 Laravel 8 中动态获取选中的单选按钮值
【发布时间】:2021-04-19 17:02:49
【问题描述】:

假设我有两个与产品定价相关的单选按钮。我想根据单选按钮的选择显示产品价格。例如,如果您选择regular price 单选按钮,我想向您显示产品的正常价格。如果您选择extended price 单选按钮,我想向您展示产品的扩展价格。我怎样才能在 Laravel 8 中做到这一点?下面是相关代码:

<h3>${{$item_price}}</h3> // this $item_price is depends on the radio button which customer select.

<div class="custom-radio">
  <input type="radio" id="opt1" class="item-price" value="100" name="item_price" checked>
  <label for="opt1" data-price="100">
    <span class="circle"></span> Regular Price
  </label>
</div>

<div class="custom-radio">
  <input type="radio" id="opt2" class="item-price" value="150" name="item_price" checked>
  <label for="opt1" data-price="150">
    <span class="circle"></span> Extended Price
  </label>
</div>

我是 laravel 的新手,我尝试使用 Form::radio("item_price", "value"),但它给了我单选按钮(DOM 元素)而不是值!

有没有什么简单的方法可以在 laravel 8 或 php 7 中获取选中/选中的单选按钮值?

【问题讨论】:

  • 你试过onclick事件来获取data-price的值吗?
  • @Psycho 我其实是想避免 js 方式。

标签: php laravel laravel-8 php-7.3


【解决方案1】:
<input type="radio" value="1" name="gt" checked>
<label>Man</label>
<input type="radio" value="0" name="gt">
<label>Women</label>

controller:
$sex = $request->gt;
//$sex = 1 or 0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多