Commit d6b5ea7e3ed12ac9a7cc2cf555c8021d5e39d221

Authored by Eriksen Costa Paixão
1 parent 2c5cd457
Exists in master

#36 by Eriksen: Corrigido bug durante carregamento de estados de um país via XMLHttpRequest

Showing 1 changed file with 32 additions and 32 deletions   Show diff stats
ieducar/intranet/public_municipio_cad.php
@@ -65,7 +65,7 @@ class indice extends clsCadastro @@ -65,7 +65,7 @@ class indice extends clsCadastro
65 var $operacao; 65 var $operacao;
66 var $idsis_rev; 66 var $idsis_rev;
67 var $idsis_cad; 67 var $idsis_cad;
68 - 68 +
69 var $idpais; 69 var $idpais;
70 70
71 function Inicializar() 71 function Inicializar()
@@ -110,9 +110,9 @@ class indice extends clsCadastro @@ -110,9 +110,9 @@ class indice extends clsCadastro
110 { 110 {
111 $objTemp = new clsPais(); 111 $objTemp = new clsPais();
112 $lista = $objTemp->lista( false, false, false, false, false, "nome ASC" ); 112 $lista = $objTemp->lista( false, false, false, false, false, "nome ASC" );
113 - if ( is_array( $lista ) && count( $lista ) ) 113 + if ( is_array( $lista ) && count( $lista ) )
114 { 114 {
115 - foreach ( $lista as $registro ) 115 + foreach ( $lista as $registro )
116 { 116 {
117 $opcoes["{$registro['idpais']}"] = "{$registro['nome']}"; 117 $opcoes["{$registro['idpais']}"] = "{$registro['nome']}";
118 } 118 }
@@ -128,13 +128,13 @@ class indice extends clsCadastro @@ -128,13 +128,13 @@ class indice extends clsCadastro
128 $opcoes = array( "" => "Selecione" ); 128 $opcoes = array( "" => "Selecione" );
129 if( class_exists( "clsUf" ) ) 129 if( class_exists( "clsUf" ) )
130 { 130 {
131 - if( $this->idpais ) 131 + if( $this->idpais )
132 { 132 {
133 $objTemp = new clsUf(); 133 $objTemp = new clsUf();
134 $lista = $objTemp->lista( false, false, $this->idpais, false, false, "nome ASC" ); 134 $lista = $objTemp->lista( false, false, $this->idpais, false, false, "nome ASC" );
135 - if ( is_array( $lista ) && count( $lista ) ) 135 + if ( is_array( $lista ) && count( $lista ) )
136 { 136 {
137 - foreach ( $lista as $registro ) 137 + foreach ( $lista as $registro )
138 { 138 {
139 $opcoes["{$registro['sigla_uf']}"] = "{$registro['nome']}"; 139 $opcoes["{$registro['sigla_uf']}"] = "{$registro['nome']}";
140 } 140 }
@@ -148,7 +148,7 @@ class indice extends clsCadastro @@ -148,7 +148,7 @@ class indice extends clsCadastro
148 } 148 }
149 $this->campoLista( "sigla_uf", "Estado", $opcoes, $this->sigla_uf ); 149 $this->campoLista( "sigla_uf", "Estado", $opcoes, $this->sigla_uf );
150 150
151 - 151 +
152 // text 152 // text
153 $this->campoTexto( "nome", "Nome", $this->nome, 30, 60, true ); 153 $this->campoTexto( "nome", "Nome", $this->nome, 30, 60, true );
154 // $this->campoNumero( "area_km2", "Area Km2", $this->area_km2, 6, 6, false ); 154 // $this->campoNumero( "area_km2", "Area Km2", $this->area_km2, 6, 6, false );
@@ -228,39 +228,39 @@ $pagina->addForm( $miolo ); @@ -228,39 +228,39 @@ $pagina->addForm( $miolo );
228 // gera o html 228 // gera o html
229 $pagina->MakeAll(); 229 $pagina->MakeAll();
230 ?> 230 ?>
231 -<script>  
232 - 231 +<script type="text/javascript">
233 document.getElementById('idpais').onchange = function() 232 document.getElementById('idpais').onchange = function()
234 { 233 {
235 - var campoPais = document.getElementById('idpais').value; 234 + var campoPais = document.getElementById('idpais').value;
236 235
237 - var campoUf= document.getElementById('sigla_uf');  
238 - campoUf.length = 1;  
239 - campoUf.disabled = true;  
240 - campoUf.options[0].text = 'Carregando estado...'; 236 + var campoUf= document.getElementById('sigla_uf');
  237 + campoUf.length = 1;
  238 + campoUf.disabled = true;
  239 + campoUf.options[0].text = 'Carregando estado...';
241 240
242 - var xml_uf = new ajax( getUf );  
243 - xml_uf.envia( "public_uf_xml.php?pais="+campoPais ); 241 + var xml_uf = new ajax(getUf);
  242 + xml_uf.envia('public_uf_xml.php?pais=' + campoPais);
244 } 243 }
245 244
246 -function getUf( xml_uf ) 245 +function getUf(xml_uf)
247 { 246 {
248 - var campoUf = document.getElementById('sigla_uf');  
249 - var DOM_array = xml_uf.getElementsByTagName( "uf" ); 247 + var campoUf = document.getElementById('sigla_uf');
  248 + var DOM_array = xml_uf.getElementsByTagName('estado');
250 249
251 - if(DOM_array.length)  
252 - {  
253 - campoUf.length = 1;  
254 - campoUf.options[0].text = 'Selecione um estado';  
255 - campoUf.disabled = false; 250 + if (DOM_array.length)
  251 + {
  252 + campoUf.length = 1;
  253 + campoUf.options[0].text = 'Selecione um estado';
  254 + campoUf.disabled = false;
256 255
257 - for( var i = 0; i < DOM_array.length; i++ )  
258 - {  
259 - campoUf.options[campoUf.options.length] = new Option( DOM_array[i].firstChild.data, DOM_array[i].getAttribute("sigla_uf"),false,false);  
260 - }  
261 - }  
262 - else  
263 - campoUf.options[0].text = 'O pais não possui nenhum estado'; 256 + for (var i = 0; i < DOM_array.length; i++) {
  257 + campoUf.options[campoUf.options.length] = new Option(
  258 + DOM_array[i].firstChild.data, DOM_array[i].getAttribute('sigla_uf'),
  259 + false, false);
  260 + }
  261 + }
  262 + else {
  263 + campoUf.options[0].text = 'O pais não possui nenhum estado';
  264 + }
264 } 265 }
265 -  
266 </script> 266 </script>
267 \ No newline at end of file 267 \ No newline at end of file