Código HTML:
<script> function tomar_datos(){ var hporId=document.getElementById("horario").value; var dporId=document.getElementById("mdia").value; var text="text"; var tex="tex"; var id_per = "<?php echo $row_id[0] ;?>"; var pc = "SELECT mnombre from materias where mdia = "+ dporId +" and horario = "+ hporId +" and alumnos_idalumnos = "+ id_per +";"; document.getElementById("hor").innerHTML="<input type="+text+" maxlength="+100+" name="+tex+" value="+"<?php echo mysql_query(pc) ?>"+" />"; } </script>