1 votes

Select PHP and MySQL dependents

Greetings, I am creating a web application to register job vacancy using PHP, MySQL and a little Javascript. My problem is that I want to filter by level of education for that does not show all the records. I thought to use a switch inside PHP but it seems that does not work. As a tip, the first select is not need to pull from Database, since I only need one key included in the value of "option" with which, I do the LIKE in the query. If you have a solution using these three tools (I want to avoid Ajax and jQuery because they do not domino so much and I'm setback with this solution), I would appreciate beforehand. Attached the code:

<div content>
    <table background="../img/201.png" cellspacing="21" align="center">
        <tr>
            <td>

                <br /> 
            </td>
        </tr>
        <form action="getQna.php" method="post">
        <tr>
            <td>
                Seleccionar el nivel educativo:
                <br />
                <select name="nivelE" id="nivelE" onchange="nivelEduc()">
                    <option value="ShowAll" selected="selected">Seleccione nivel:</option>
                    <option value="24DDI">Educaci&oacute;n Inicial</option>
                    <option value="24DJN">Preescolar</option>
                    <option value="24DPR">Primaria</option>
                    <option value="24DST">Secundarias T&eacute;cnicas</option>

                </select>
                <br />
                <br />
                Seleccionar la plaza vacante:
                <br />
                <select name="plazaS" id="plazaS" onchange="alerta()">
                    <option value="showAll" selected="selected">Seleccione:</option>
     <?php
    require_once 'config.php';


    $stmt = $dbcon->prepare('SELECT * FROM analitico where estatus="V"');
    $stmt->execute();

    while($row=$stmt->fetch(PDO::FETCH_ASSOC))
    {
        extract($row);
        ?>
        <option value="<?php $concat= $plaza . " " . $ct; echo $concat; ?>"><?php echo $plaza; ?></option> 
        <?php
    }
    ?>              
            </select>

        </td>
    </tr>
    <tr>
        <td>
            <label>Clave de Centro de Trabajo:</label>
                <br />
                <table>
                    <tr>
                        <td>
                        <input type="hidden" id="plaza" name="plaza"/> <!--Aquí se desconcatena-->
                        <input type="text"  id="ct" name="ct" readonly="readonly"/>
                        <input type="hidden" id="nivel" name="nivel"/>
                        </td>
                    </tr>
                </table>
        </td>
    </tr>
    <td align="justify">
    <!--Aquí se va a poner a elegir lo de la vacancia temporal o permanente--->
        Ingrese el inicio de la vacancia:
        <br />

            <input type="text" name="qna_ini" id="qna_ini" onkeypress="return isNumber(event)" maxlength="6" autocomplete="off"/>
    </td >
    <td align="justify">
        Ingrese el fin de la vacancia:
        <br />
            <input type="text" name="qna_fin" id="qna_fin" onkeypress="return isNumber(event)" maxlength="6" autocomplete="off" />

    </td>
    <tr>
        <td>
        <input type="submit" />
        </form>
        </td>
    </tr>
</table>

function alerta()
{   
     var x = document.getElementById("plazaS").value,
    separador = " ", // un espacio en blanco
    arregloDeSubCadenas = x.split(separador);
    console.log(arregloDeSubCadenas);
    document.getElementById("ct").value = arregloDeSubCadenas[1];
    document.getElementById("plaza").value = arregloDeSubCadenas[0];
}

function nivelEduc()
{
    var nivel=document.getElementById("nivelE").value;
    console.log(nivel);
    document.getElementById("nivel").value=nivel;
}

2voto

Kevin Hernández Points 141

There is a library of JQuery is very easy to implement, will prevent you to use AJAX, you just have to export it and add to your filters is called zelect.

Basically, you will only need these lines:

<select id="async-backed-zelect"></select>
$('#async-backed-zelect').zelect({ placeholder:'Plz select..' });

I think you would be very useful if what you want is to filter your select and minimize development times. Is that deals with JQuery but it is a cost for a faster development, and fewer lines of code.

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X