Dynamic Combobox with php

0

Looking for the solution to this I come here.

I am programming a small dynamic combobox with php, to the point.

I have my combobox 1 which would be months and the combobox 2 that would be days, the idea is that by selecting February in the > combobox 1 , automatically the combobox 2 only prints me 28 days and not 31.

<select name="Meses del año">
 <option value="0">Selecione un mes del año</option>

	<?php 
		for ($i=0; $i < sizeof($meses); $i++) { 
	 ?>
	 <option value="<?php echo $meses[i]; ?>">
	 	<?php 
	 		echo $meses[$i];
	 	 ?>
	 </option>
	 <?php 
	}
	  ?>

 </select>

 <select name="Dias del mes">
 	<option value="0">Seleccione un dia del mes</option>
 	<?php 
 		for ($x=0; $x <count($dia) ; $x++) { 
 	 ?>
 	 <option value="<?php echo $dia[$x];?>">
 	 	<?php 
 	 		echo $dia[$x];
 	 	 ?>
 	 </option>
 	 <?php 
 		}
 	  ?>
 </select>

It is a small portion of the code in question, what is above is the array of months and days.

    
asked by David Ramirez 23.03.2017 в 22:25
source

1 answer

0

It is impossible for you to do this with dynamic PHP, at the time of making the request the PHP is processed on the server and the answer on the browser side and you will only have HTML, so when you "hear" the change in the combobox to the month of February, nothing will happen (Or with the months of 30 days).

(You can make a new call to the server by selecting the month localhost:8080/?mes=febrero and dynamically fill the array $dia and refresh the page)

What you could do would be to write a Javascript script to dynamically modify the fields, or your most popular jQuery library, or through an AJAX call, call back PHP to make the change.

You can also use libraries like Datapicker to get rid of problems with Scripts and HTML.

    
answered by 23.03.2017 / 23:38
source