Fill fields according to the chosen option

0

I want to fill two fields according to the option chosen by the user. My code is this:

<div class="form-group">
                Cuatrimestre
                <select id="cuatrimestre" name="cuatrimestre" class="form control">
                  <?php
                    $bd = new ManejoDB();
                    $bd->conectar_base($x,$x,$x);
                    $sql = "SELECT * FROM x";
                    $bd->qBD($sql);
                    while ($row = $bd->obtenerReg()){
                      //echo "<option value='".$row['id']."'>'".$row['descripcion']."'</option>";
                      echo "<option>".$row['descripcion']."</option>";
                    }
                  ?>
                </select>
              </div>
                            <div class="form-group">
                                Desde
                    <input type="text" name="desde" id="desde">
                            </div>
                            <div class="form-group">
                                Hasta
                    <input type="text" name="hasta" id="hasta">
                            </div>    

code js

$(document).ready(function(){
            $('#cuatrimestre').on('change',function(){
                var cuatrimestre = $(this).val();
                $.ajax({
                    url : "getCuatri.php",
                    dataType: 'json',
                    type: 'POST',
                    async : false,
                    data : { cuatrimestre : cuatrimestre},
                    success : function(data) {
                        userData = json.parse(data);
                        $('#desde').val(userData.fecha_desde);
                        $('#hasta').val(userData.fecha_hasta);
                    }
                }); 
            });
        });

getCuatri.php

$bd = new ManejoDB();
$bd->conectar_base($x,$x,$x);
$sql = "SELECT fecha_desde, fecha_hasta from Encuesta_Compras_Cuatrimestre where descripcion= '".$descripcion."' ";
$bd->qBD($sql);
$row = $bd->obtenerReg();
json_encode($row); die;

That's my code but it does not work. I do an include and the js I have it separate and I also include it.

What am I wrong? Thank you very much, best regards

    
asked by GAL 23.02.2017 в 20:18
source

1 answer

0

I still can not comment: (

in your file getCuatri.php you still need to print the result

$bd = new ManejoDB();
$bd->conectar_base($x,$x,$x);
$sql = "SELECT fecha_desde, fecha_hasta from Encuesta_Compras_Cuatrimestre where descripcion= '".$descripcion."' ";
$bd->qBD($sql);
$row = $bd->obtenerReg();
echo json_encode($row); die; 

You only need echo before json_encode

    
answered by 23.02.2017 / 20:26
source