469,345 Members | 5,921 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,345 developers. It's quick & easy.

Fill a double combo

3
Hi guys I have a little problem solving a query for an xml file, i have to put in a drop down list all the "Provincias" from a selected "Departamento", my xml is like this
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <departamentos>
  3.   <departamento>
  4.     <id>1</id>
  5.     <nombre>Lima</nombre>
  6.       <provincias>
  7.           <provincia>
  8.               <id>1</id>
  9.               <nombre>Lima</nombre>
  10.           </provincia>
  11.           <provincia>
  12.               <id>2</id>
  13.               <nombre>Barranca</nombre>
  14.           </provincia>
  15.       </provincias>
  16.   </departamento>
  17.   <departamento>
  18.     <id>2</id>
  19.     <nombre>La Libertad</nombre>
  20.       <provincias>
  21.           <provincia>
  22.               <id>1</id>
  23.               <nombre>Trujillo</nombre>
  24.           </provincia>
  25.           <provincia>
  26.               <id>2</id>
  27.               <nombre>Chepen</nombre>
  28.           </provincia>
  29.       </provincias>
  30.   </departamento>
  31. </departamentos>
  32.  
and my code in javascript is like this:

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head runat="server">
  6.     <title>Página sin título</title>
  7.  
  8.     <script language="javascript" type="text/javascript">
  9.     var http_request = false;
  10.     function makeRequest(url, parameters, functionName){
  11.         if(window.XMLHttpRequest){
  12.             http_request = new XMLHttpRequest();
  13.             if(http_request.overrideMimeType){
  14.                 http_request.overrideMimeType('text/xml');
  15.             }
  16.         }
  17.         else if(window.ActiveXObject){
  18.             try{
  19.                 http_request = new ActiveXObject("Msxml2.XMLHTTP");
  20.             }
  21.             catch (e){
  22.                 try{
  23.                     http_request = new ActiveXObject("Microsoft.XMLHTTP");
  24.                 }
  25.                 catch (e){}
  26.             }
  27.         }
  28.         if(!http_request){
  29.             alert('No se pudo cargar correctamente el objeto XMLHTTPRequest');
  30.             return false;
  31.         }
  32.  
  33.         var cadena = "http_request.onreadystatechange = " + functionName;
  34.         eval(cadena);
  35.         http_request.open('GET', url + parameters, true);
  36.         http_request.send(null);
  37.     }    
  38.  
  39.     function do_xml(functionName){
  40.         makeRequest('data.xml', '', functionName);
  41.     }
  42.     function SetDepartamentos(){
  43.         if(http_request.readyState == 4){
  44.             if(http_request.status == 200){
  45.                 var xmldoc = http_request.responseXML;
  46.                 var depas = xmldoc.getElementsByTagName('departamento');
  47.                 var ddl = document.getElementById('DDLdepartamentos');
  48.                 for(var i = 0;i<depas.length;i++){
  49.                     ddl.options[ddl.options.length]=new Option(depas[i].getElementsByTagName("nombre")[0].firstChild.nodeValue, depas[i].getElementsByTagName("id")[0].firstChild.nodeValue);
  50.                    }
  51.             }
  52.             else{
  53.                 alert('Hubo un problema al realizar la peticion');
  54.             }           
  55.         }
  56.     }
  57.     function SetProvincias(){
  58.     if(http_request.readyState == 4){
  59.             if(http_request.status == 200){
  60.                 var xmldoc = http_request.responseXML;
  61.                 var provi = xmldoc.getElementsByTagName('provincia');
  62.                 var depa = document.getElementById('DDLdepartamentos').nodeValue;
  63.                 var ddl = document.getElementById('DDLprovincias');
  64.                 for(var i = 0;i<provi.length;i++){
  65.                     dll.options[dll.options.length]=new Option(depa.provi[i].getElementsByTagName("nombre")[0].firstChild.nodevalue, depa.provi[i].getElementsByTagName("id")[0].firstChild.nodeValue);
  66.                 }
  67.             }
  68.             else{
  69.                 alert('Hubo un problema al realizar la peticion');
  70.             }           
  71.         }
  72.     }
  73.     </script>
  74.  
  75. </head>
  76. <body onload="do_xml(SetDepartamentos)">
  77.     <form id="form1" runat="server" >
  78.         Departamentos<br />
  79.         <select id="DDLdepartamentos" name="DDLdepartamentos" onchange="do_xml(SetProvincias)">
  80.         </select><br />
  81.         Provincias<br />
  82.         <select id="DDLprovincias" name="DDLprovincias">
  83.         </select>
  84.     </form>
  85. </body>
  86. </html>
  87.  
May 6 '07 #1
5 4563
acoder
16,027 Expert Mod 8TB
Welcome to TSDN.

So what's the problem?
May 7 '07 #2
Italus
3
Thx for the wellcome
My problem is that i cant fill the second combo box
May 11 '07 #3
iam_clint
1,208 Expert 1GB
whats the error?
May 11 '07 #4
pbmods
5,821 Expert 4TB
Is it bigger than a breadbox?

Sorry; I thought we were playing 20 questions :P
May 12 '07 #5
iam_clint
1,208 Expert 1GB
Is it bigger than a breadbox?

Sorry; I thought we were playing 20 questions :P
what?

LOL just kidding lets stay on topic guys lets get this one answered!
May 12 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Sherwood Botsford | last post: by
2 posts views Thread by Joanne Lewis | last post: by
3 posts views Thread by Wajih-ur-Rehman | last post: by
2 posts views Thread by Jeremy Dillinger | last post: by
5 posts views Thread by Tark Siala | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.