0
<div class="select_list">
    <div class="labels">Category:</div>
    <?php
        if(!isset($_POST['postbtn)){
            echo "<script>$(document).ready(function(){
                $('.category').val(0);
            })
            </script>";
        }
        echo "<select name='category' id='catg_list' class='list_catg'>
            <option value='0'";
                if(isset($_POST['category']) && $_POST['category']=='0'){
                    echo "selected";
                }
            echo">none</option>";
            $query = mysql_query("SELECT id, name from table1");
            while($query_fetch = mysql_fetch_assoc($query)){
                echo "<option value='".$query_fetch['id']."'";
                if(isset($_POST['category']) && $_POST['category']==$query_fetch['id'])
                {
                    echo "selected";
                }
                echo ">".$query_fetch['name']."</option>";
            }
            echo "</select>";
    ?>
</div>

上記のコードの問題は、送信が完了した後も選択された要素が選択されたままになることです。フォームが正常に送信されたときに「なし」に戻るには、選択オプションが必要です。どうすればそれができますか?

4

2 に答える 2