Código:
<script type="text/javascript"> function loadidcarrera() { var cbocarrera=document.getElementById("cbocarrera"); var id=cbocarrera.selectedIndex; var req=new XMLHttpRequest(); //req.overrideMimeType('text/xml'); //req.setRequestHeader("Content-Type", "text/html"); req.open("GET","matricula.php?i="+id,true); req.send(""); req.onreadystatechange = function(){ if(req.readyState==4){ if(req.status==200){ alert('ok'); } }else{ alert("Cagado"); } }; } </script> <body> <?php $cn=new mysqli("localhost","root","43781406","matricula"); $rs=$cn->query("SELECT id,especialidad FROM tb_especialidad"); $codcarrera=array(); $cont=0; if(!isset($_GET['i'])) { $_GET['i']=0; } ?> <form name="frmmatri" method="post" action="registrar.php"> <table border="1" align="center"> <thead> <tr> <th colspan="2"> Matricula </th> </tr> </thead> <tbody> <tr> <td>Numero</td> <td><input type="text" name="txtnum" /><input type="hidden" name="frm" value="matricula"/></td> </tr> <tr> <td>Alumno</td> <td><input type="text" name="txtalu" /></td> </tr> <tr> <td>Especialidad</td> <td> <select name="cboespecialidad" onchange="loadidcarrera()" id="cbocarrera"> <?php while($row=$rs->fetch_row()){?> <option><?php echo $row[1]; $idcarrera[$cont]=$row[0]; $cont++?></option> <?php }?> </select> <input type="hidden" value="<?php echo $idcarrera[$_GET['i']];?>" name="idespecialidad" /> </td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="btnreg" value="Registrar"/></td> </tr> </tbody> </table> </form> <?php echo $_GET['i']; ?> </body> </html>