Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

pensar

Passar valores do pop up para meu form .

Recommended Posts

Galera é o seguinte.

 

Nao manjo muito de javascript...

 

A minha duvida é a seguinte :

 

Tenho um formulario que antes de prenchê-lo clico no botao procurar ... que abrirá uma pop up que contem uma lista de nomes cadastrados no banco.

 

Ate ai beleza. Quero que ao clicar em um nome qualquer da lista ... a pop up feche e retorne para mim nos campos input do meu form o valor nome o rg e o cpf desse cliente., para mim continuar o prenchimento do formulario depois...

 

Fiz rapidinho uma index.php com um form e o botao procurar.. que busca a pagina detalhes.php que lista os nomes.

Isso so para testar ...

 

Segue abaixo os scripts.

 

index.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

<style type="text/css">

<!--

.style1 {

font-family: Arial, Helvetica, sans-serif;

font-size: 14px;

color: #333333;

}

-->

</style>

</head>

<script language="JavaScript" src="selecionar_campo.js"></script>

<body>

<form id="form" name="form" method="post" action="">

<p class="style1"><a href="java script:window.open('detalhes.php','','width=450,height=340,top=0,left=0,scrollbars=yes');window.history.go(9)">Procurar <img src="lupa.gif" width="15" height="15" /></a></p>

<p class="style1">Nome:

<label>

<input name="nome" type="text" id="nome" onclick="window.open('detalhes.php','janela','adress=no')">

</label>

RG:

<label>

<input name="rg" type="text" id="rg" />

</label>

CPF:

<input name="cpf" type="text" id="cpf" />

</p>

</form>

</body>

</html>

detalhes.php

<html>

<head>

<title>..:: Detalhes ::..</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="fontes.css" rel="stylesheet" type="text/css">

</head>

<body bgcolor="#FFFFFF" text="#000000" link="#000099" vlink="#000099" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="400" border="0" cellspacing="0" cellpadding="0">

<tr>

<td><img src="imagens/spacer.gif" width="1" height="3"></td>

</tr>

</table>

<?php

 

include("conexao.php");

 

$conexao = mysql_connect("$host","$user","$pass");

 

$db = mysql_select_db("$db");

 

$sql = "SELECT * FROM cad_func";

 

$resultado = mysql_query($sql)

or die ("Não foi possível realizar a consulta ao banco de dados");

 

$total = mysql_query($sql);

 

$total = mysql_num_rows($total);

 

echo "

<table width='600' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#003399'>

<tr>

<td height='22' background='imagens/fundo_titulos.jpg' bgcolor='#F7F7F7'>

<p class='Texto_form_center'>Detalhes</p></td>

</tr>";

 

$resultado=mysql_query($sql);

 

while ($linha=mysql_fetch_array($resultado)) {

 

$id = $linha["id"];

$nome = $linha["nome"];

 

$cpf = $linha["cpf"];

 

$rg = $linha["rg"];

 

 

echo "

<tr>

<td bgcolor='#FFFFFF'>

 

<p class='Texto_form_esquerda'>";

 

if (strlen($nome)<1) {} else { echo "<strong>Nome:</strong> $nome. "; }

 

 

 

 

}

echo "</table>";

 

?>

<p class="Texto_form_centro"><input name="cadastrar" type="button" onClick="java script:window.close()" id="cadastrar" style="color: #000000; font-family: Verdana; font-size: 13 px; border-style: outset; border-width: 1; background-color: #CCCCCC" value="..:: Fechar ::..">

</p>

 

</html>

Procurei no forum mas os posts relacionados nao consegui resolver

Compartilhar este post


Link para o post
Compartilhar em outros sites

você deve chamar "window.opener"window.opener.document.XXXXXX é o elemento ou objeto ao qual você quer interagir

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara nao entendi bem..você poderia me passar um exemplo disso ..?Obrigado

Compartilhar este post


Link para o post
Compartilhar em outros sites

beleza tm ferreira agora so mais uma duvida Na pop up cada nome listado sera um link ... como faço isso ? com o onlick??

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara esta dando um erro bobo de ponto e virgula mas nao to conseguindo encontrar Vou postar o erro e a linha indicada Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in c:\arquivos de programas\easyphp\www\popup\detalhes.php on line 62

echo " <tr> <td bgcolor='#FFFFFF'> <p class='Texto_form_esquerda'>";//linha 62 echo "<strong>Nome:</strong><a href="java script:transfere('nome');">$nome</a>"; }echo "</table>";

Compartilhar este post


Link para o post
Compartilhar em outros sites

echo "<strong>Nome:</strong><a href="java script:transfere('nome');">$nome</a>";Alterei mas da o mesmo erro

Compartilhar este post


Link para o post
Compartilhar em outros sites

beleza deu certo ..Continuando meu script eu clico no link do nome que aparece no pop up mas ele retorna a principal a palavra nome o que pode estar errado segue o scripts do pop up

<html><head><title>..:: Detalhes ::..</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link href="fontes.css" rel="stylesheet" type="text/css"><script>function transfere(nome) { window.opener.document.getElementById('usuario').value = nome;}</script></head><body bgcolor="#FFFFFF" text="#000000" link="#000099" vlink="#000099" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="imagens/spacer.gif" width="1" height="3"></td> </tr></table> <?php include("conexao.php");$conexao = mysql_connect("$host","$user","$pass");$db = mysql_select_db("$db");$sql = "SELECT * FROM cad_func";$resultado = mysql_query($sql)or die ("Não foi possível realizar a consulta ao banco de dados");$total = mysql_query($sql); $total = mysql_num_rows($total); echo "<table width='600' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#003399'> <tr> <td height='22' background='imagens/fundo_titulos.jpg' bgcolor='#F7F7F7'> <p class='Texto_form_center'>Detalhes</p></td> </tr>";$resultado=mysql_query($sql);while ($linha=mysql_fetch_array($resultado)) {$id = $linha["id"];$nome = $linha["nome"];$cpf = $linha["cpf"];$rg = $linha["rg"];echo " <tr> <td bgcolor='#FFFFFF'> <p class='Texto_form_esquerda'>"; echo "<strong>Nome:</strong<a href='#' onclick=transfere('nome')>$nome</a>"; }echo "</table>";?></html>

o script da principal é esse

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><style type="text/css"><!--.style1 { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #333333;}--></style></head><script language="JavaScript" src="selecionar_campo.js"></script><body><form id="form" name="form" method="post" action=""> <p class="style1"><a href="java script:window.open('detalhes.php','','width=450,height=340,top=0,left=0,scrollbars=yes');window.history.go(9)">Procurar <img src="lupa.gif" width="15" height="15" /></a></p> <p class="style1">Nome: <label> <input name="nome" type="text" id="usuario"> </label>      RG: <label> <input name="rg" type="text" id="rg" /> </label>  CPF: <input name="cpf" type="text" id="cpf" /> </p></form></body></html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

certo e na funçaõ javascript em cima eu altero algo??

Compartilhar este post


Link para o post
Compartilhar em outros sites

naum, você tem q lembrar q o q tá "embaixo"(chamada da função) é o valor q estará dentro da variável da função, ex:<input onclick="teste('OLÁ')">e na função:function teste(frase){alert(frase);//O VALOR EXIBIDO AKI SERÁ "OLÁ"}entendeu????????

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara alterei como você disse olha como esta

<html><head><title>..:: Detalhes ::..</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link href="fontes.css" rel="stylesheet" type="text/css"><script>function transfere(nome) { window.opener.document.getElementById('usuario').value = nome;}</script></head><body bgcolor="#FFFFFF" text="#000000" link="#000099" vlink="#000099" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="imagens/spacer.gif" width="1" height="3"></td> </tr></table> <?php include("conexao.php");$conexao = mysql_connect("$host","$user","$pass");$db = mysql_select_db("$db");$sql = "SELECT * FROM cad_func";$resultado = mysql_query($sql)or die ("Não foi possível realizar a consulta ao banco de dados");$total = mysql_query($sql); $total = mysql_num_rows($total); echo "<table width='600' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#003399'> <tr> <td height='22' background='imagens/fundo_titulos.jpg' bgcolor='#F7F7F7'> <p class='Texto_form_center'>Detalhes</p></td> </tr>";$resultado=mysql_query($sql);while ($linha=mysql_fetch_array($resultado)) {$id = $linha["id"];$nome = $linha["nome"];$cpf = $linha["cpf"];$rg = $linha["rg"];echo " <tr> <td bgcolor='#FFFFFF'> <p class='Texto_form_esquerda'>"; echo "<strong>Nome:</strong<a href='#' onclick=transfere('& $nome &')>$nome</a>"; }echo "</table>";?></html>

mas nao transfere para a principal valor nehum

Compartilhar este post


Link para o post
Compartilhar em outros sites

Testei aqui colocqui assim echo "<strong>Nome:</strong<a href='#' onclick=transfere(' " & $nome & " ')>$nome</a>";e deu esse erro nao esta listando ! C` $@ ! C` $@

Compartilhar este post


Link para o post
Compartilhar em outros sites

O tm colocquei com você passou mas esta acontecendo algo estranho ele esta listando 5 nomes cadastrados e quando clico somente no terceiro nome que ele retorna na principal . Os outros eu clico e nao acontece nadaO que pode ser ...?Ah e sobre sua dica o o Google Suggestions poderia me explicar melhorFalow,..

Compartilhar este post


Link para o post
Compartilhar em outros sites

Segue o fonte Index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><style type="text/css"><!--.style1 { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #333333;}--></style></head><script language="JavaScript" src="selecionar_campo.js"></script><body><form id="form" name="form" method="post" action=""> <p class="style1"><a href="java script:window.open('detalhes.php','','width=450,height=340,top=0,left=0,scrollbars=yes');window.history.go(9)">Procurar <img src="lupa.gif" width="15" height="15" /></a></p> <p class="style1">Nome: <label> <input name="nome" type="text" id="usuario"> </label>      RG: <label> <input name="rg" type="text" id="rg" /> </label>  CPF: <input name="cpf" type="text" id="cpf" /> </p></form></body></html>

detalhes.php > pop up

<html><head><title>..:: Detalhes ::..</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link href="fontes.css" rel="stylesheet" type="text/css"><script>function transfere(nome) { window.opener.document.getElementById('usuario').value = nome;}</script></head><body bgcolor="#FFFFFF" text="#000000" link="#000099" vlink="#000099" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="imagens/spacer.gif" width="1" height="3"></td> </tr></table> <table width='600' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#003399'> <tr> <td height='22' background='imagens/fundo_titulos.jpg' bgcolor='#F7F7F7'> <p class='Texto_form_center'>Detalhes</p></td> </tr> <tr> <td bgcolor='#FFFFFF'> <p class='Texto_form_esquerda'><strong>Nome:</strong><a href='#' onclick=transfere('Carlos da Silva')>Carlos da Silva</a> <tr> <td bgcolor='#FFFFFF'> <p class='Texto_form_esquerda'><strong>Nome:</strong><a href='#' onclick=transfere('Araquem Ibrahim Midon')>Araquem Ibrahim Midon</a> <tr> <td bgcolor='#FFFFFF'> <p class='Texto_form_esquerda'><strong>Nome:</strong><a href='#' onclick=transfere('Paulo')>Paulo</a> <tr> <td bgcolor='#FFFFFF'> <p class='Texto_form_esquerda'><strong>Nome:</strong><a href='#' onclick=transfere('Marcelo da Silva')>Marcelo da Silva</a> <tr> <td bgcolor='#FFFFFF'> <p class='Texto_form_esquerda'><strong>Nome:</strong><a href='#' onclick=transfere('Diogo Dias')>Diogo Dias</a></table></html>

So esta me retornando o nome Paulo os demais nao ....

Compartilhar este post


Link para o post
Compartilhar em outros sites

Deu certo aqui tmValew.. vou dar uma estudada nele aqui pois quero que ao clicar ele traga o cpf e rg tambem ..Quanto a sua dica achei muito massa mesmo.... baixei uns scripts de exemplo ..para dar uma olhada .. e surgiu uma duvida ele busca no banco essas informações?è que nao encontrei as instruções do banco ...

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.