0

さまざまな店舗の商品を追加できる食料品リストのタイプがあります。

現在、商品番号と数量を投稿し、[送信] を押してアイテムを食料品リストに追加するフォームがあります (下の表)。

<form action="<?php echo $current_file.$id; ?>" method="POST">

    Store:  <select>
                    <option value="gross1">Store 1</option>
                    <option value="gross2">Store 2</option>
                    <option value="gross3">Store 3</option>
            </select>

    Art no: <input type="text" size="15" name="number"  /> 

    Quantity: <input type="text" size="3" name="q" />

    <input type="submit" value="Add item" />

</form>

<table>
    <tr>
        <th>
            Art no
        </th>
        <th>
            Article name
        </th>
        <th>
            Price
        </th>
        <th>
            Quantity
        </th>
        <th>
            Total
        </th>
    </tr>

ストアのアイテム リストは mysql テーブルに格納されているため、ドロップ ダウン選択リストからストア (または必要に応じてテーブル) を選択します。しかし問題は、アイテムを選択しているストアがストア 1 ではない場合、送信を押すたびに何度もストアを選択するのはかなりイライラすることです。

ある種の GET 変数を使用して選択した店舗を指定するスクリプトを使用できるとは思いません。既に GET を使用して選択した食料品リストを指定しているためです。ページの更新後に選択したストアをサイトに記憶させる別の方法はありますか?

前もって感謝します!

4

2 に答える 2

0

PHP では、通常、POSTed 値に基づいてオプションに対して SELECTED を設定します。ただし、select タグに名前を設定する必要があります。

これについてグーグルで検索してみましたか?

于 2013-03-29T23:04:14.807 に答える
0

同様の問題があり、迅速な解決策が必要でした.ドロップダウンリストから値を選択して送信すると、ページがリロードされ、選択した値を保持せずにドロップダウンリストがリセットされます(選択した値が送信された場合でも($ _GET))ユーザーが選択した値をユーザーに見てもらいたかったので、私にとってこの問題は純粋に審美的なものでした。

// Change the parent dropdown selected value to the currently selected value
    $(window).load(function() {

        // Get url attributes which should contain the $_POST or $_GET value and split it. You have to refine this in case you have multiple attributes

        var str=window.location.href; var n=str.split("=");

         // This should be the selected value attribute
         var myAttrVal= n[1];

       // check all options and grab the value (or whatever other unique identifier you're using). Check this value against your url value and when they match, add the selected attribute to that option.
        $('#selectID option').each(function() {

            var selectedOptVal = $(this).attr('value');

            if ( myAttrVal  == selectedOptVal) {

                $(this).attr('selected', 'selected');
            }
        });

    });

これを行うにはもっと良い方法があると確信していますが、問題を解決する方法についてのアイデアが得られることを願っています.

于 2015-05-11T17:13:44.073 に答える