Foros del Web » Programando para Internet » ASP Clásico »

[SOLUCIONADO] Que con el evento onchange me carge un combobox

Estas en el tema de Que con el evento onchange me carge un combobox en el foro de ASP Clásico en Foros del Web. Hola, Estoy programando en asp, lo que hace el código que escribire mas abajo es que, se escribe un valor dentro del input type=text y ...
  #1 (permalink)  
Antiguo 03/06/2013, 02:17
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años
Puntos: 7
Que con el evento onchange me carge un combobox

Hola,
Estoy programando en asp, lo que hace el código que escribire mas abajo es que, se escribe un valor dentro del input type=text y cuando le doy al boton me carga un combobox con los resultados de la select.
Código ASP:
Ver original
  1. <html>
  2.     <head>
  3.     </head>
  4.     <body>
  5.         <%
  6.         Set conn = Server.createobject("adodb.connection")
  7.         Set tablabase = Server.createobject("adodb.recordset")
  8.         conn.open "coplan"
  9.         %>
  10.         <table border="5">
  11.             <tr>
  12.                 <td>
  13.                     <form action="referencias_revisiones.asp" method = "post" id="form4" name="buscarPedido">
  14.                         <table border="2" align="center">
  15.                             <tr>
  16.                                 <td align="center" colspan="2">
  17.                                     <u><big><big><strong><tt>REFERENCIAS - REVISIONES</tt></strong></big></big></u>
  18.                                 </td>
  19.                             </tr>
  20.                             <tr>
  21.                                 <td>
  22.                                     Introduce proyecto:
  23.                                     <input type="text" name="pedido" size=20 value="">                     
  24.                                     <input type="submit" name="buscarRevisiones" value="Buscar">
  25.                                 </td>
  26.                                 <td>
  27.                                     <%if request.Form("pedido")<>"" then%>
  28.                                         <%Dim valortext
  29.                                         valortext = request.Form("pedido")%>
  30.                                         <%tablabase.open "select distinct revision from r_coplan where pedido ='"&valortext&"'", conn
  31.                                         Dim i
  32.                                         i = 0%>
  33.                                         <select name="Nombre">                                     
  34.                                             <%while not (tablabase.eof)%>
  35.                                                 <%Session(tablabase("revision")) = tablabase("revision").value
  36.                                                 Dim revision
  37.                                                 revision = tablabase("revision").value
  38.                                                 'response.write revision%>
  39.                                                 <option value="<%=i%>"><%=revision%></option>
  40.                                                 <%i = i+1%>
  41.                                                 <%tablabase.moveNext%>
  42.                                             <%wend%>
  43.                                         </select>
  44.                                         <%tablabase.Close%>
  45.                                     <%end if%>
  46.                                 </td>
  47.                             </tr>
  48.                         </table>
  49.                     </form>
  50.                 </td>
  51.             </tr>
  52.         </table>
  53.         <%Set tablabase = Nothing
  54.         Conn.Close
  55.         Set Conn = Nothing%>
  56.     </body>
  57. </html>

Lo que quiero es quitar el botón y que cuando el input type=text tenga el evento onchange este me cargue lo que cargo al darle al botón en el caso anterior.

He estado mirando y parece ser que hay que utilizar javascript, pero ya que no se utilizarlo no se como obtener el valor del input type=text ni como cargar el combo o poner el código donde hago la select y cargo el combo.

He echo algo así pero ya no se como seguir:
Código ASP:
Ver original
  1. <html>
  2.     <head>
  3.     <SCRIPT>
  4.     <!--
  5.     function CargarCombo() {
  6.         //obtener el valor del input pedido y que me haga lo que hace dentro del if request.form("pedido")
  7.         pedido.focus()
  8.     }
  9.     //-->
  10.     </SCRIPT>
  11.     </head>
  12.     <body>
  13.         <%
  14.         Set conn = Server.createobject("adodb.connection")
  15.         Set tablabase = Server.createobject("adodb.recordset")
  16.         conn.open "coplan"
  17.         %>
  18.         <table border="5">
  19.             <tr>
  20.                 <td>
  21.                     <form action="referencias_revisiones.asp" method = "post" id="form4" name="buscarPedido">
  22.                         <table border="2" align="center">
  23.                             <tr>
  24.                                 <td align="center" colspan="2">
  25.                                     <u><big><big><strong><tt>REFERENCIAS - REVISIONES</tt></strong></big></big></u>
  26.                                 </td>
  27.                             </tr>
  28.                             <tr>
  29.                                 <td>
  30.                                     Introduce proyecto:
  31.                                     <input type="text" name="pedido" size=20 value="" onchange="CargarCombo()">  
  32.                                     <%'<input type="submit" name="buscarRevisiones" value="Buscar">%>
  33.                                 </td>
  34.                                 <td>
  35.                                     <%if request.Form("pedido")<>"" then%>
  36.                                         <%Dim valortext
  37.                                         valortext = request.Form("pedido")
  38.                                         'response.write valortext%>
  39.                                         <%tablabase.open "select distinct revision from r_coplan where pedido ='"&valortext&"'", conn
  40.                                         'response.write "select distinct revision from r_coplan where pedido ='"&valortext&"'"
  41.                                         Dim i
  42.                                         i = 0%>
  43.                                         <select name="Nombre">                                     
  44.                                             <%while not (tablabase.eof)%>
  45.                                                 <%Session(tablabase("revision")) = tablabase("revision").value
  46.                                                 Dim revision
  47.                                                 revision = tablabase("revision").value
  48.                                                 'response.write revision%>
  49.                                                 <option value="<%=i%>"><%=revision%></option>
  50.                                                 <%i = i+1%>
  51.                                                 <%tablabase.moveNext%>
  52.                                             <%wend%>
  53.                                         </select>
  54.                                         <%tablabase.Close%>
  55.                                     <%end if%>
  56.                                 </td>
  57.                             </tr>
  58.                         </table>
  59.                     </form>
  60.                 </td>
  61.             </tr>
  62.         </table>
  63.         <%Set tablabase = Nothing
  64.         Conn.Close
  65.         Set Conn = Nothing%>
  66.     </body>
  67. </html>

¿Alguien me puede echar una mano?
__________________
Gracias por todo;

Un saludo
  #2 (permalink)  
Antiguo 03/06/2013, 03:21
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años
Puntos: 7
Respuesta: Que con el evento onchange me carge un combobox

Ha conseguido coger el valor del textbox en la funcion javascript de esta forma:

Código Javascript:
Ver original
  1. function CargarCombo(form) {
  2.     var valortext;
  3.     valortext = form.pedido.value
  4.     alert(valortext)
  5. }
Código ASP:
Ver original
  1. <input type="text" name="pedido" size=20 value="" onchange="CargarCombo(this.form)">

Ahora lo que necesito es que esa funcion javascript me haga el select y me carge el combobox con los valores que obtenga.

¿Alguien me puede echar una mano?
__________________
Gracias por todo;

Un saludo
  #3 (permalink)  
Antiguo 03/06/2013, 08:21
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años
Puntos: 7
Respuesta: Que con el evento onchange me carge un combobox

Ya lo he solucionado, he utilizado AJAX para ello.

Os dejo el código por si a alguien le sirve de ayuda.

referencias_revisiones.asp
Código ASP:
Ver original
  1. <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
  2. <html>
  3.     <head>
  4.     <script language="javascript" type="text/javascript">
  5.     function nuevoAjax(){
  6.         /* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
  7.         lo que se puede copiar tal como esta aqui */
  8.         var xmlhttp=false;
  9.         try{
  10.            // Creacion del objeto AJAX para navegadores no IE
  11.            xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  12.         }
  13.         catch(e){
  14.            try{
  15.                // Creacion del objet AJAX para IE
  16.                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  17.            }
  18.            catch(E) { xmlhttp=false;
  19.            }
  20.         }
  21.         if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  22.             xmlhttp=new XMLHttpRequest();
  23.         }
  24.         return xmlhttp;
  25.     }
  26.  
  27.     function cargaAplicacion(){
  28.         //alert ("entra1");
  29.         var valor=document.getElementById("pedido").value;
  30.         //alert (valor);        
  31.        
  32.         if (valor==0){         
  33.            document.getElementById("celda_aplicacion").innerHTML=" Escribe un proyecto previamente";
  34.         }
  35.         else{
  36.             //alert ("entra2");
  37.             ajax=nuevoAjax();
  38.             ajax.open("GET", "careferencias.asp?pedido="+valor, true);
  39.             ajax.onreadystatechange=function(){
  40.                if (ajax.readyState==1){
  41.                    combo=document.getElementById("celda_aplicacion");
  42.                    combo.length=0;
  43.                    var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Cargando...";
  44.                    combo.appendChild(nuevaOpcion);
  45.                    combo.disabled=false;      
  46.                }
  47.                if (ajax.readyState==4){
  48.                     //alert ("entra3");
  49.                    //alert(ajax.responseText);
  50.                    document.getElementById("celda_aplicacion").innerHTML=ajax.responseText;
  51.                }
  52.            }
  53.            ajax.send(null);
  54.         }
  55.     }
  56.     </script>
  57.  
  58.     </head>
  59.     <body>
  60.         <%
  61.         Set conn = Server.createobject("adodb.connection")
  62.         Set tablabase = Server.createobject("adodb.recordset")
  63.         conn.open "coplan"
  64.         %>
  65.         <table border="5">
  66.             <tr>
  67.                 <td>
  68.                     <form action="referencias_revisiones.asp" method = "post" id="form4" name="buscarPedido">
  69.                         <table border="2" align="center">
  70.                             <tr>
  71.                                 <td align="center" colspan="2">
  72.                                     <u><big><big><strong><tt>REFERENCIAS - REVISIONES</tt></strong></big></big></u>
  73.                                 </td>
  74.                             </tr>
  75.                             <tr>
  76.                                 <td>
  77.                                     Introduce proyecto:
  78.                                     <input type="text" name="pedido" id="pedido" size=20 value="" onchange="cargaAplicacion()">
  79.                                 </td>
  80.                                 <td id="celda_aplicacion">
  81.                                 </td>
  82.                             </tr>
  83.                         </table>
  84.                     </form>
  85.                 </td>
  86.             </tr>
  87.         </table>
  88.         <%Set tablabase = Nothing
  89.         Conn.Close
  90.         Set Conn = Nothing%>
  91.     </body>
  92. </html>

careferencias.asp
Código ASP:
Ver original
  1. <%
  2.     valor = Request("pedido")
  3.     'response.write valor
  4.    
  5.     'if len(valor)>3 then
  6.    
  7.     Set conn = Server.createobject("adodb.connection")
  8.     Set tablabase = Server.createobject("adodb.recordset")
  9.     conn.open "coplan"
  10.        
  11.        
  12.     tablabase.open "select distinct revision from r_coplan where pedido ='"&valor&"'", conn
  13.    
  14.     response.write "<select class=""combo"" id=""aplicacion"" name=""aplicacion""><option></option>"
  15.  
  16.     if tablabase.eof then
  17.         response.write "<option></option>"
  18.     else
  19.         do until tablabase.eof
  20.             response.Write "<option value=""" & tablabase("revision") & """>" & Server.HtmlEncode(tablabase("revision")) & "</option>"
  21.             tablabase.movenext
  22.         loop
  23.     end if
  24.     tablabase.close
  25.     set tablabase=nothing
  26.    
  27.     response.write "</select>"
  28. %>

__________________
Gracias por todo;

Un saludo

Etiquetas: asp, combobox, evento, html, nombre, onchange, select, tabla, valor
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:38.