簡體   English   中英

如何從輸入類型=“數字”顯示值

[英]How to display value from input type=“number”

我有一個輸入字段,其中包含該項目的數量 如果用戶更改數量值,我想更新會話中存儲的值。 我的問題是我無法獲得“價值”。

<form method="post">
    <input type="number" class="form-control text-center" name="quantityInput" size="1" maxlength="2" value="'.$cart_itemDisplay['quantity'].'">
    <button class="btn btn-info btn-sm" method="POST" name="refreshBtn"><i class="fa fa-refresh"></i></button>
</form>

當我嘗試存儲值時:

$quantityOfItemToAdjust = $_POST['quantityInput'];

完整代碼:

echo '
                                        <tbody>
                                            <tr>
                                                <td data-th="Product">
                                                    <div class="row">
                                                        <div class="col-sm-2 hidden-xs"><img src="img/movies/'.$imageName.'" alt="..." class="img-responsive"/></div>
                                                        <div class="col-sm-10">
                                                            <h4 class="nomargin">'.$nameOfProduct.'</h4>
                                                            <p>'.$productDesc.'</p>
                                                        </div>
                                                    </div>
                                                </td>
                                                <td data-th="Price">£'.$priceOfItem.'</td>
                                                <td data-th="Quantity">
                                                    <form method="post" action="tickets.php">
                                                        <input type="number" class="form-control text-center" name="quantityInput" size="1" maxlength="2" value="'.$cart_itemDisplay['quantity'].'">

                                                    </form>
                                                    </td>
                                                <td data-th="Subtotal" class="text-center">1.99</td>
                                                <td class="actions" data-th="">

                                                    <form method="post" action="tickets.php">
                                                        <button class="btn btn-info btn-sm" method="submit" name="refreshBtn"><i class="fa fa-refresh"></i></button>
                                                        <input name="item_to_adjust" type="hidden" value="'.$idOfItem.'"/>




                                                        <button class="btn btn-danger btn-sm"><i class="fa fa-trash-o"></i></button>    
                                                    </form>


                                                </td>
                                            </tr>
                                        </tbody>
                                        ';

您應該使用提交而不是按鈕,並且表單需要執行操作。

<form method="post" action="yourpage.php">
<input type="number" class="form-control text-center" name="quantityInput" size="1" maxlength="2" value="'.$cart_itemDisplay['quantity'].'">
<input type="submit" class="btn btn-info btn-sm" name="refreshBtn" value="Refresh">
</form>

這將起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM