Segue o meu código completo para você entender: HTML página pai: <form action="<? echo $path_modulos_cmdb_html; ?>/tab_gerais/cep/cad_cep_bd.php" method="post" id="EnviaForm" name="EnviaForm">
<table class="bordasimples" style="width:100%">
<tr>
<td colspan="5"></td>
</tr>
<tr>
<td width="13%"></td>
<td width="20%" colspan="4">Código CEP:<br>
<input type="text" name="txt_CodigoCep" id="txt_CodigoCep" maxlength="9" size="9" tabindex="1" alt="Pressione F9 ou clique na lupa para consultar" title="Pressione F9 ou clique na lupa para consultar">
<input type="image" tabindex="2" name="BuscaCep" id="BuscaCep" src="<? echo $path_img_html;?>/lupa.jpg" class="lupa" alt="Pressione F9 ou clique na lupa para consultar" title="Pressione F9 ou clique na lupa para consultar"/>
</td>
</tr>
<tr>
<td width="13%"></td>
<td colspan="4">Endereço:<br>
<input type="text" name="txt_Endereco" id="txt_Endereco" maxlength="100" size="60" tabindex="2"><br>
</td>
</tr>
<tr>
<td width="13%"></td>
<td colspan="4">Bairro:<br>
<input type="text" name="txt_Bairro" id="txt_Bairro" maxlength="70" size="50" tabindex="3">
</td>
</tr>
<tr>
<td width="13%"></td>
<td width="22%" colspan="2">UF:<br>
<select name="cmb_Uf" id="cmb_Uf" tabindex="4">
<?
//popula o combo com as UFs
include "$path_includes_combo/cmb_uf.php";
?>
</select>
</td>
<td width="40%">Município:<br>
<select name="cmb_Municipio" id="cmb_Municipio" tabindex="5">
<option value=''>Selecione</option>
<? //populado via arquivo form_busca_cep.php ?>
</select>
<input type="hidden" name="hdn_Municipio" id="hdn_Municipio"/>
</td>
<td width="13%"></td>
</tr>
<tr>
<td colspan="5">
<input type="hidden" name="hdn_acao" id="hdn_acao">
</td>
</tr>
</table>
<table class="bordasimples" style="width:90%">
<tr>
<td colspan="7"></td>
</tr>
<tr>
<td width="25%"></td>
<td width="14%">Identificador:<br><input type="text" id="txt_id_cep" name="txt_id_cep" class="disabled" disabled></td>
<td width="8%"></td>
<td width="18%"></td>
<td ></td>
<td width="7%"></td>
</tr>
<tr>
<td></td>
<td>Criado Por:<br><input type="text" id="txt_nm_usuario_inclusao" name="txt_nm_usuario_inclusao" class="disabled" disabled></td>
<td></td>
<td>Data de Criação:<br><input type="text" id="txt_dt_cep_inclusao" name="txt_dt_cep_inclusao" class="disabled" disabled></td>
<td></td>
</tr>
<tr>
<td></td>
<td>Modificado Por:<br><input type="text" id="txt_nm_usuario_alteracao" name="txt_nm_usuario_alteracao" class="disabled" disabled></td>
<td></td>
<td>Data de Modificação:<br><input type="text" id="txt_dt_cep_alteracao" name="txt_dt_cep_alteracao" class="disabled" disabled></td>
<td><br></td>
</tr>
<tr>
<td colspan="5"></td>
</tr>
</table>
</form>
Script da página pai:
window.PreencheMunicipio = function() {
var val_uf = $(this).find(':selected').val();
var val_municipio = $("#hdn_Municipio").val();
//$("#cmb_Municipio").load('/fapsl/includes/combo/cmb_municipio.php?uf='+val_uf+'&municipio');
$("#cmb_Uf").change();
}
//Ao mudar o combo de UF, popular
$("#cmb_Uf").change(
function(){
var val_uf = $(this).find(':selected').val();
var val_municipio = $("#hdn_Municipio").val();
$.post('/fapsl/includes/combo/cmb_municipio.php',{uf: val_uf, municipio: val_municipio},
function(resposta)
{
$("#cmb_Municipio").html(resposta);
if (val_uf !='')
{
$("#cmb_Uf").valid();
}
}
);
}
);
//Validar após selecionar registro
$("#cmb_Municipio").change(
function()
{
$("#cmb_Municipio").valid();
}
);
HTML da página filha: popup
<?
session_start();
ob_start();
include "/var/www/fapsl/path.php";
include "$path_includes/conecta_bd.inc";
include_once "$path_includes/includePerdeSessao.php";
?>
<html>
<head>
<title>Consulta de CEPs</title>
<script type="text/javascript" src="<? echo $path_jquery_html; ?>/jquery.js"></script>
<script type="text/javascript" src="<? echo $path_jquery_html; ?>/jquery.alerts.js"></script>
<script type="text/javascript" src="<? echo $path_jquery_html; ?>/jquery.tablesorter.js"></script>
<script type="text/javascript" src="<? echo $path_modulos_html; ?>/script/form_ordenar.js"></script>
<link rel="stylesheet" type="text/css" href="<? echo $path_css_html;?>/tabelas.css" />
<link rel="stylesheet" type="text/css" href="<? echo $path_css_html; ?>/jquery.alerts.css" />
</head>
<body onUnload="java script:fecha();">
<div align="center">
<table class="tablesorter" width="80%" id="sort">
<?
$num_cep=str_replace("-","",$_REQUEST["cep"]);
$query="SELECT * FROM consulta_cep('$num_cep')";
$rs=pg_query($dbconn,$query);
if ($rs)
{
if (pg_num_rows($rs)<>0)
{
?>
<thead>
<tr>
<th width="18%">Código CEP<img src="<? echo $path_img_html?>/setas_ordenacao.gif"/></th>
<th>Endereço<img src="<? echo $path_img_html?>/setas_ordenacao.gif"/></th>
<th width="20%">Bairro<img src="<? echo $path_img_html?>/setas_ordenacao.gif"/></th>
<th width="20%">Municipio<img src="<? echo $path_img_html?>/setas_ordenacao.gif"/></th>
<th width="8%">UF<img src="<? echo $path_img_html?>/setas_ordenacao.gif"/></th>
</tr>
</thead>
<tbody>
<? for($i=0; $i<pg_num_rows($rs); $i++)
{
$rs_fetch = pg_fetch_row($rs);
$nr_cep=$rs_fetch[0];
$nr_cep_parte1 = substr($nr_cep, 0, 5);
$nr_cep_parte2 = substr($nr_cep, 4, 3);
$nr_cep = $nr_cep_parte1."-".$nr_cep_parte2;
$id_cep=$rs_fetch[1];
$nm_logradouro=$rs_fetch[2];
$nm_bairro = $rs_fetch[3];
$id_municipio = $rs_fetch[4];
$nm_municipio = $rs_fetch[5];
$id_uf = $rs_fetch[6];
$nm_uf = $rs_fetch[7];
$dt_cep_inclusao=$rs_fetch[8];
$str_time=strtotime($dt_cep_inclusao);
if (date(Y,$str_time)!='1969')
$dt_cep_inclusao=date("d/m/Y G:i:s", $str_time);
else
{
$dt_cep_inclusao='';
}
$dt_cep_alteracao=$rs_fetch[9];
$str_time=strtotime($dt_cep_alteracao);
if (date(Y,$str_time)!='1969')
$dt_cep_alteracao=date("d/m/Y G:i:s", $str_time);
else
{
$dt_cep_alteracao='';
}
$nm_usuario_inclusao=$rs_fetch[10];
$nm_usuario_alteracao=$rs_fetch[11];
$id_usuario_inclusao=$rs_fetch[12];
$id_usuario_alteracao=$rs_fetch[13];
$str_parametros=$id_cep.',"'.$nr_cep.'",'.'"'.$nm_logradouro.'",'.'"'.$nm_bairro.'",'.'"'.$id_municipio.'",'.'"'.$nm_municipio.'",'.'"'.$id_uf.'",'.'"'.$nm_uf.'","'.$dt_cep_inclusao.'","'.$dt_cep_alteracao.'","'.$nm_usuario_inclusao.'","'.$nm_usuario_alteracao.'","'.$id_usuario_inclusao.'","'.$id_usuario_alteracao.'"';
echo "<tr>";
echo "<td>";
echo "<a href='' OnClick='cap_valores($str_parametros)' id='sigla_ug'>";
echo $nr_cep;
echo "</a>";
echo "</td>";
echo "<td>";
echo $nm_logradouro;
echo "</td>";
echo "<td>";
echo $nm_bairro;
echo "</td>";
echo "<td>";
echo $nm_municipio;
echo "</td>";
echo "<td>";
echo $nm_uf;
echo "</td>";
echo "</tr>";
}
}
else
{
if(pg_num_rows($rs)==0)
{
$str_mensagem="A Consulta não trouxe registros";
$str_erro="Não há registros semelhantes na base";
echo "<script type='text/JavaScript'>";
echo "$(document).ready( function() {";
echo 'jAlert("'.$str_erro.'","'.$str_mensagem.'",
function(resposta){
if (resposta==true)
{
window.close();
}
});';
echo "}); </script>";
}
}
}
else
{
$str_mensagem="Ocorreu um erro na consulta dos dados.";
$str_erro = pg_last_error($dbconn);
$str_erro = str_replace("'","",$str_erro);
$str_erro = str_replace("\n","",$str_erro);
echo "<script type='text/JavaScript'>";
echo "$(document).ready( function() {";
echo 'jAlert("'.$str_erro.'","'.$str_mensagem.'",
function(resposta){
if (resposta==true)
{
window.close();
}
});';
echo "}); </script>";
}
?>
</tbody>
</table>
</div>
</body>
</html>
Script da Página filha: popup
function cap_valores(id_cep, int_cod_cep, str_endereco, str_bairro, int_cod_municipio, str_municipio, int_cod_uf, str_uf, dt_cep_inclusao, dt_cep_alteracao, nm_usuario_inclusao, nm_usuario_alteracao, id_usuario_inclusao, id_usuario_alteracao)
{
var str_municipio = int_cod_municipio + "_" + str_municipio;
var str_uf = int_cod_uf + "_" + str_uf;
window.opener.document.getElementById("hdn_acao").value="alt";
window.opener.document.getElementById("txt_CodigoCep").value=int_cod_cep;
window.opener.document.getElementById("txt_Endereco").value=str_endereco;
window.opener.document.getElementById("hdn_Municipio").value=str_municipio;
window.opener.document.getElementById("txt_Bairro").value=str_bairro;
window.opener.document.getElementById("cmb_Uf").value =str_uf;
window.opener.PreencheMunicipio();
window.opener.document.getElementById("txt_id_cep").value=id_cep;
window.opener.document.getElementById("txt_nm_usuario_inclusao").value=nm_usuario_inclusao;
window.opener.document.getElementById("txt_dt_cep_inclusao").value=dt_cep_inclusao;
window.opener.document.getElementById("txt_nm_usuario_alteracao").value=nm_usuario_alteracao;
window.opener.document.getElementById("txt_dt_cep_alteracao").value=dt_cep_alteracao;
window.close();
}
function fecha()
{
var acao=window.opener.document.getElementById("hdn_acao").value;
if (acao=='con')
{
window.opener.document.getElementById("hdn_acao").value = 'inc';
}
} Muito obrigada!