I Have created a 2 drop-down bar. 1)for selecting the floor. 2) depend on 1st drop-downbar[dynamically changed]
<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>
dropdown 2 code Using 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: Now how i will take the value of selected value of Floor and Block in php ? I need the value of both variable to use in my db.
Que-2:Suppose i press submit button with some value and then were some error occur,then i come back to this page dropdown-1 is continued with previous selected value but dropdown-2 does not show value acccording to dropdown-1.
After submit-->error occure -->return to the same page. That does not show the flat dropdown[dropdown-2]
Maybe the problem lies with php variable that is used for firing the query for insertion process, check for SQL datatype & values you are inserting.
I set an Enum data type for some of my columns. by correcting that I can insert data through PHP.
var floorByCategory = { 0: ["1", "2", "3", "4"], 1: ["5", "6", "7", "8"], 2: ["9", "10", "11", "12"] }
<select class="custom-select" id="selectFloor" name="selectFloor" onChange="changecat(this.value),getflatvalue();"> <option disabled="true" selected>Select floor</option> <option value="0"> Floor-0 </option> <option value="1"> Floor-1 </option> <option value="2"> Floor-2 </option> </select>
I need to set floor and flat value like this.as per my "enum" data type. by correcting the values value can be insert.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.