hola foro !!!
esperando me puedan ayudar les doy las gracias de antemano y es con lo siguiente.
tengo una tabla con 3 campos y son 95 registro 1.- (CLAVE), 2.-(AREA) y 3.- (TITULAR)
Ejemplo
clave área titular
1.1 RECURSOS HUMANOS Lic. Alberto Goméz
lo que pretendo es mostrar la clave en un combo y cuando el usuario de clic en cualquiera de las claves
mostrar en un input type="text" el area y en otro input type="text" el titular como podría hacer esto?,,
cabe mencionar que estoy aprendiendo php
buscando me encontre este script que hace mas o menos lo que deseo, pero se no tengo aun los conocimientos de php menos de javascript
<? /* require("conecta.php"); $busca = "Select * From claves"; $lista = mysqli_query($conectado,$busca); $datos = mysqli_fetch_array($lista); $areglo = array($datos); while ($fila = mysqli_fetch_array($lista)) { echo $fila['clave']; echo $fila['area']; echo " "; echo $fila['titular']; echo "<br>"; } */ ?> <!DOCTYPE html> <html lang="es"> <head> <title>Captura Oficios</title> <meta charset="utf-8"> <script> //Este arreglo simula tu tabla. tabla = [ {'clave':'11','area':'Direccion General de Administracion','titular':'Lic. Alberto Vazquez'}, {'clave':'22','area':'Direcccion de Recursos Humanos','titular':'C. Juan Perez'}, {'clave':'33','area':'Recursos Materiales','titular':'Dra. Guadalupe Reyes'} ]; window.onload = function(){ // Poblamos el Select, esto lo deberias hacer con php select = document.getElementById('lstRegistros'); tabla.forEach(function(registro){ select.innerHTML += "<option value='"+registro.clave+"' data-area='"+registro.area+"' >"+registro.titular+"</option>"; }); // Agregamos el evento para que cuando cambie la seleccion actualice los inputs select.addEventListener("change",putInfo); } function putInfo(){ optionSelected = this.options[this.selectedIndex]; clave = this.value; // Obtengo el valor del Select area = optionSelected.dataset.area; // Obtengo el valor del dataset area titular = optionSelected.textContent; //Obtengo el texto del option seleccionado //Asigno los valores a los inputs document.getElementById("txtClave").value=clave; document.getElementById("txtTitular").value=titular; document.getElementById("txtArea").value=area; } </script> </head> <body> <select id="lstRegistros"> <option value="" data-area=""></option> </select> <br /> <table> <tr> <td>Clave:</td> <td> <input type="text" id="txtClave" /></td> </tr> <tr> <td>Area:</td> <td><input type="text" id="txtArea" /></td> </tr> <tr> <td>Titular:</td> <td><input type="text" id="txtTitular" /></td> </tr> </table> </body> </html>
espero respuesta con ansiedad !!!!!!
GRACIAS