如何从 javascript 到 php 获取数据库和 js 下拉行为的值

我创建了一个 2 下拉栏。1)选择楼层。2)取决于第一个下拉栏[动态更改]


下拉 1 代码

<select class="custom-select" id="selectFloor" name="selectFloor" onChange="changecat(this.value),getflatvalue();"> 

                                    <option disabled="true" selected>Select floor</option>

                                    <option value="floor_0">    Floor-0     </option>

                                    <option value="floor_1">    Floor-1     </option>

                                    <option  value="floor_2">   Floor-2     </option>

                                </select>

下拉 2 代码使用 JAVASCRIPT


<script type="text/javascript">

    

    var floorByCategory = {

    floor_0: ["Flat-1", "Flat-2", "Flat-3", "Flat-4"],

    floor_1: ["Flat-5", "Flat-6", "Flat-7", "Flat-8"],

    floor_2: ["Flat-9", "Flat-10", "Flat-11", "Flat-12"]

}


function changecat(value) {

        if (value.length == 0) document.getElementById("category").innerHTML = "<option></option>";

        else {

            var catOptions = "";

            for (categoryId in floorByCategory[value]) {

                 catOptions += "<option>" + floorByCategory[value][categoryId]

                 + "</option>";

            }

            document.getElementById("category").innerHTML = catOptions;

        }

    }

**getflatvalue(); code for this function**


 function getflatvalue()//taking selected value of floor Option bar.

    {

        var flatval=document.getElementById("selectFloor").value;

        console.log(flatval);

    }

Que-1:现在我将如何在php中获取 Floor 和 Block 的选定值?我需要这两个变量的值才能在我的数据库中使用。

Que-2:假设我按下带有某个值的提交按钮,然后发生了一些错误,然后我返回此页面 dropdown-1 继续使用先前选择的值,但 dropdown-2 不显示根据 dropdown-1 的值。

http://img4.mukewang.com/63a54bcc000185d813660762.jpg

http://img1.mukewang.com/63a54bd8000168aa13630769.jpg

、提交后-->发生错误-->返回同一页面。那不显示平面下拉菜单 [dropdown-2]

蝴蝶不菲
浏览 90回答 3
3回答

天涯尽头无女友

也许问题在于用于触发插入过程查询的 php 变量,检查您插入的 SQL 数据类型和值。

拉莫斯之舞

改正后这个问题-2也解决了...现在floor和flat两个值都重置了,我们需要手动选择两个。

饮歌长啸

我为一些列设置了枚举数据类型。通过更正我可以通过 PHP 插入数据。var floorByCategory = {&nbsp; &nbsp; 0: ["1", "2", "3", "4"],&nbsp; &nbsp; 1: ["5", "6", "7", "8"],&nbsp; &nbsp; 2: ["9", "10", "11", "12"]}<select class="custom-select" id="selectFloor" name="selectFloor" onChange="changecat(this.value),getflatvalue();">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option disabled="true" selected>Select floor</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="0">&nbsp; Floor-0&nbsp; &nbsp; &nbsp;</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="1">&nbsp; Floor-1&nbsp; &nbsp; &nbsp;</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option&nbsp; value="2"> Floor-2&nbsp; &nbsp; &nbsp;</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </select>我需要像这样根据我的“枚举”数据类型设置下限值和平面值。 通过更正值可以插入值。
打开App,查看更多内容
随时随地看视频慕课网APP