the idea is that by clicking on any option of a select depending on this I fill in the fields of my form I am working with php, mysql: this is my select
<select name="ruta" id="ruta" class="form-control" onchange="showService(this.value)">
<?php
$link = mysqli_connect("localhost", "root", "");
mysqli_select_db($link, "stp17");
$tildes = $link->query("SET NAMES 'utf8'"); //Para que se muestren las tildes correctamente
$result = mysqli_query($link, "SELECT * FROM rutas");
while ($filas = mysqli_fetch_array($result)){
?>
<option value="<?php echo $filas['id']; ?>"><?php echo $filas['nomCorto']; ?></option>
<?php
}
mysqli_free_result($result);
mysqli_close($link);
?>
</select>
In this div
<div id="nomCorto"></div>
alamaceno the data but I do not know how to put them in text boxes
Script
function showService(str) {
if (str=="") {
document.getElementById("nomCorto").innerHTML="";
return;
}
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("nomCorto").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getservice.php?service="+str,true);
xmlhttp.send();
}
and this is my php file
<?php
$link = mysqli_connect("localhost", "root", "");
mysqli_select_db($link, "stp17");
$service = $_GET['service'];
$query = mysqli_query($link,"SELECT * FROM rutas WHERE id = '".$service."'");
while($row = mysqli_fetch_array($query)) {
?>
<p><?php echo $row['descripcion']; ?></p>
<?php
}
echo "</table>";
mysqli_close($link);
?>