cfajardo Posted April 11, 2013 Share Posted April 11, 2013 Hi, I need to fill a drop-down box from another drop-down box in an ASP using AJAX, I was following the AJAX Database example, but I don't get the data, so don't know what am I doing wrong, could anyone please help me trying to figure out what's wrong or if you have an example of how to fill a drop-down box once you change the value of another drop-down box? here is my code: AJAX.JS function showSubject(str){var xmlhttp;if (str=="") { document.getElementById("materias").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("materias").innerHTML=xmlhttp.responseText; } }xmlhttp.open("GET","materiaslista.asp?q="+str,true);xmlhttp.send();} MATERIASPAGE.ASP<% response.expires=-1 Set base=Server.CreateObject("ADODB.Connection")base.ConnectionString = "DSN=acc"base.Open strSql="Select * from tblMaterias where Carrera="strSql=strSql & "'" & request.querystring("q") & "'" set rsMat=Server.CreateObject("ADODB.recordset")rsMat.Open strSql,base response.write("<table>") do until rstMat.eof for each x in rstMat.Fieldsresponse.write("<tr><td><b>" & x.name & "</b></td>") response.write("<td>" & x.value & "</td></tr>") next rstMat.movenext loop response.write("</table>") %> STUDENTS.ASP I have: <script type="text/javascript" src="ajax.js"></script> <form method="post" action="save_data.asp?ac=1" name="Form1"><tr><td class="style5"><span lang="es-pa"><strong>Carrera</strong></span>:</td> <td class="style5"> <select name="carrera" onchange="showSubject(this.value)" > <option value="">Seleccione una carrera!</option> <%while not rstCar.eof%><option value="<%=rstCar.Fields("id")%>"><%=rstCar.Fields("carrera")%></option><%rstCar.MoveNextwend%></select></td></tr><tr> <td class="style5"><strong>Materias:</strong></td> <td class="style5"> <div id="materias">TEXTO</div></td></tr></form> Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted April 11, 2013 Share Posted April 11, 2013 Select elements don't have a value property, they have a selectedIndex property and an options array. The value would be this.options[this.selectedIndex].value. Your code lists materiaslista.asp as the page to send the request to, but you called that page MATERIASPAGE.ASP. You may also need to URL-encode the value in the querystring if it contains special characters. Link to comment Share on other sites More sharing options...
cfajardo Posted April 11, 2013 Author Share Posted April 11, 2013 (edited) Thank you for your response, So you mean that the value should be: <select name="carrera" onchange="showSubject(this.options[this.selectedIndex].value)" >? For the name of the pages, I renamed it, thank you, actually, the querystring is getting an id value, numeric value. Regards, Edited April 11, 2013 by cfajardo Link to comment Share on other sites More sharing options...
cfajardo Posted April 12, 2013 Author Share Posted April 12, 2013 What I don't understand is why id doesn't work on the same the example http://www.w3schools.com/ajax/ajax_database.asp is written? Regards, Link to comment Share on other sites More sharing options...
cfajardo Posted April 12, 2013 Author Share Posted April 12, 2013 It's working now, Thank you!! Regards Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now