Combo Box to paint an input

0

I have this code that contains two functions and both work the only thing that I want is to change that instead of being shown in a select they are shown in an input type text readonly

The HTML that contains the select that formats the combo boxes:

<td>
    <select class="form-control" name="acro_proyecto" id="acro_proyecto"  onchange="change_documento1();  change_documento2();" required>
            <option value="<?php echo isset($obj_categoria) ? $obj_categoria->__GET('proyecto') : ''; ?>"><?php echo isset($obj_categoria) ? $obj_categoria->__GET('proyecto') : ''; ?> </option> 
            <?php
            $pdo = new PDO('mysql:host=localhost;dbname=dmsgeneratorcode', 'root', '');
           $pdo->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
           $stmt = $pdo->prepare('Select acro_proyecto from proyectos');
           $stmt->execute();
           while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
           echo '<option>' . $row['acro_proyecto'] . '</option>';
                                    }
                                    ?>
    </select>
</td>

This is one of the select that fills the combo box

<th style="text-align:center;">Oferta/Proyecto</th>
   <td >
     <select  class="form-control" name="oferta_proyecto" id="oferta_proyecto" >
            <option value="<?php echo isset($obj_categoria) ? $obj_categoria->__GET('oferta_proyecto') : ''; ?>"><?php echo isset($obj_categoria) ? $obj_categoria->__GET('oferta_proyecto') : ''; ?> </option>    
      </select>
  </td>

This is the one that applies the functions when you select something in the should perform these two functions:

Ajax:

function change_documento1()
        {
            var acro_proyecto = $("#acro_proyecto").val();
            var compania1 = $("#compania1").val();
            var acro_subcategoria = $("#acro_subcategoria").val();
            var acro_documento = $("#acro_documento").val();
            $.ajax({
                type: "POST",
                url: "numdocumento.php",
                // fijate en el & para separar las variables
                data: "acro_proyecto=" + acro_proyecto + "&compania1=" + compania1 + "&acro_subcategoria=" + acro_subcategoria + "&acro_documento=" + acro_documento,
                cache: false,
                success: function (response)
                {
                    $("#num_documento").html(response);
                }
            });

        }

        function change_documento2()
        {
            var acro_proyecto = $("#acro_proyecto").val();

            $.ajax({
                type: "POST",
                url: "ofertaproyecto.php",
                data: "acro_proyecto=" + acro_proyecto,
                cache: false,
                success: function (response)
                {
                    //alert(response);return false;
                    $("#oferta_proyecto").html(response);
                }
            });

        }

And they call another php file as seen, for example:

bidproject.php

 <?php

include('dbConfig.php');
$acro_proyecto = $_POST['acro_proyecto'];
$sql= "select oferta_proyecto from proyectos where acro_proyecto='$acro_proyecto'";
$query = $db->query($sql);

while($res = $query->fetch_assoc()){
echo '<option    value="'.$res['oferta_proyecto'].'">'.$res['oferta_proyecto'].'</option>'; 
}

?>

The structure is as follows:

All the html code and the ajax functions are in a file called index.php and ofertaproyecto.php is a different file that makes the combobox.

I know they have SQL vulnerabilities but as it is by intranet and we are in a hurry to finish it they have indicated to us that we do it this way and it will be modified later.

    
asked by Alberto Cepero de Andrés 02.06.2017 в 10:01
source

0 answers