Categories: javascript, php, database

How to get value from javascript to php for database and js dropdown behaviour

3 answers

I Have created a 2 drop-down bar. 1)for selecting the floor. 2) depend on 1st drop-downbar[dynamically changed]

dropdown 1 code

<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.

enter image description here

enter image description here After submit-->error occure -->return to the same page. That does not show the flat dropdown[dropdown-2]

All answers to this question, which has the identifier 61205947

The best answer:

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.

After correcting this question-2 is also solved... Now the floor and flat both value are reset, and we need to select both manually.

enter image description here

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data