PHP 열려진 팝업창(새창/자식창)에서 부모창으로 결과 선택후 전송하기
페이지 정보
본문
자식창에서 부모창으로 정보를 넘기기 예제 입니다
우편번호 찾기에도 응용하면 쉽게 적용할 수 있습니다
< 예제. 1 >
1. 부모창
<form name="폼네임">
<script type="text/javascript">
function openChild(url, field) {
var opt = "toolbar=no, resizable=yes, scrollbars=yes, location=no, resize=no, menubar=no, directories=no, copyhistory=0, width=470, height=250, top=330, left=370";
window.open(url, 'new_window', opt);
}
</script>
<input type=text name='항목1' value=''> <a href="#" onclick="openChild('search.php', this);">검색</a><br>
<input type=text name='항목2' value=''>
2. 자식창 search.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>검색</title>
<style>
* {-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;}
a{text-decoration:none;}
th, td { font-size:12px; height:30px; }
</style>
</head>
<body>
<div style="margin:20px;">
<div style="letter-spacing:-1px; padding: 0 20px 5px 20px;">
검색을 원하시는 단어를 입력한 다음, <font color="#ED0063"><strong>찾기</strong></font>를 누르세요.<br>
</div>
<div style="padding: 0 15px 0 20px; text-align:center">
<form action="<?php echo $PHP_SELF; ?>" method="post">
<input name="s" type="text" size="30" value="<?php echo $_POST['s']; ?>">
<input type="submit" value=" 찾기 ">
</form>
</div>
<div style="padding: 0;">
<script type="text/javascript">
function copy(a, b) {
opener.폼네임.항목1.value = a;
opener.폼네임.항목2.value = b;
window.close();
}
</script>
<?php
if ($_POST["s"]) {
$sql = "select * from `디비테이블` where (code1 like '%{$_POST['s']}%') ";
//echo $sql;
$qry = sql_query($sql);
while($row = sql_fetch_array($qry)) {
$code1 = $row['code1'];
$code2 = $row['code2'];
?>
<div><a href="#" onclick="copy('<?php echo $code; ?>','<?php echo $univ; ?>')"><?php echo "[{$code1}] {$code2}"; ?></a></div>
<?php
}
} else {
echo "<div style=\"text-align:center; height:100px; font-size:12px; padding-top:20px;\">검색하지 않았거나, 검색결과가 없습니다.</div>";
}
?>
</div>
</div>
</body>
</html>
< 예제. 2 >
1. 부모창
<script>
function openChild(url, field) {
var opt = "toolbar=no, resizable=yes, scrollbars=yes, location=no, resize=no,menubar=no, directories=no, copyhistory=0, width=400, height=200, top=100, left=100";
window.name = "ori_window";
window.open(url, 'new_window', opt);
}
</script>
<input type="radio" name="order_type" value="free">
초대코드인증 : <input type="text" name="free_num" id="free_num" style="width:100px;" readonly>
<input style="padding:2px 20px; height:24px;" onclick="openChild('search.php', this);" type="button" value="코드검색"><br>
2. 자식창 search.php
<?php
//include_once "_common.php";
$mysql_host = "localhost";
$mysql_user = "아이디";
$mysql_password = "비밀번호";
$mysql_db = "데이타베이스";
$dbconn = mysqli_connect($mysql_host,$mysql_user,$mysql_password,$mysql_db);
//$dbconn = mysqli_connect(G5_MYSQL_HOST,G5_MYSQL_USER,G5_MYSQL_PASSWORD,G5_MYSQL_DB); // 그누보드5
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>무료코드 검색</title>
<script language="javascript">
function ok() {
if (document.code.free.value=="" ) {
alert("\ 인증할 번호를 입력하여 주시기바립니다.");
return;
}
document.code.submit();
}
function InStrData(free_num){
opener.document.form.free_num.value = free_num;
window.close();
}
</script>
<style>
* {-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;}
a{text-decoration:none;}
th, td { font-size:12px; height:30px; }
</style>
</head>
<body>
<form name="code" method="post" action="search.php">
<div>
<img src="img/freecode_01.gif" width="9" height="33" align="absmiddle">
<strong>무료 코드번호</strong>
</div>
<div style="text-align:center; height:50px;">무료 코드번호
<input name="free" type="text" size="20" value="<?php echo $_POST['free']; ?>">
<input type="button" class="input_box" value="인증하기" onClick="ok()">
</div>
<div style="height:90px;">
<?php
if ($_POST['free']) {
$sql="select * from `디비테이블`_free where freecode='{$_POST['free']}'";
//echo $sql;
$qry = mysqli_query($dbconn,$sql);
$row = mysqli_fetch_array($qry);
if (!$row['freecode']) {
echo "입력하신 <strong>{$free}</strong> 의 번호가 올바르지 않습니다.<br>";
} else {
$freecode = $row['freecode'];
$wdate = $row['wdate'];
if ($row['wdate']) {
echo "입력하신 <strong>{$free}</strong> 는 {$row['wdate']}에 등록된 번호입니다.";
} else {
?>
<strong><?php echo $freecode; ?></strong> 인증되었습니다.<br>
사용된 코드는 등록완료후 재신청이 불가합니다.<br>
[ <a href="javascript:InStrData('<?php echo $freecode; ?>')"><strong>사용하기</strong></a> ]
<?php
}
}
}
?>
</div>
<div height="15" bgcolor="#F0F0F0"><center><a href='#' onClick='javascript:window.close();'>창닫기</a></center></div>
</form>
</body>
</html>
우편번호 찾기에도 응용하면 쉽게 적용할 수 있습니다
< 예제. 1 >
1. 부모창
<form name="폼네임">
<script type="text/javascript">
function openChild(url, field) {
var opt = "toolbar=no, resizable=yes, scrollbars=yes, location=no, resize=no, menubar=no, directories=no, copyhistory=0, width=470, height=250, top=330, left=370";
window.open(url, 'new_window', opt);
}
</script>
<input type=text name='항목1' value=''> <a href="#" onclick="openChild('search.php', this);">검색</a><br>
<input type=text name='항목2' value=''>
2. 자식창 search.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>검색</title>
<style>
* {-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;}
a{text-decoration:none;}
th, td { font-size:12px; height:30px; }
</style>
</head>
<body>
<div style="margin:20px;">
<div style="letter-spacing:-1px; padding: 0 20px 5px 20px;">
검색을 원하시는 단어를 입력한 다음, <font color="#ED0063"><strong>찾기</strong></font>를 누르세요.<br>
</div>
<div style="padding: 0 15px 0 20px; text-align:center">
<form action="<?php echo $PHP_SELF; ?>" method="post">
<input name="s" type="text" size="30" value="<?php echo $_POST['s']; ?>">
<input type="submit" value=" 찾기 ">
</form>
</div>
<div style="padding: 0;">
<script type="text/javascript">
function copy(a, b) {
opener.폼네임.항목1.value = a;
opener.폼네임.항목2.value = b;
window.close();
}
</script>
<?php
if ($_POST["s"]) {
$sql = "select * from `디비테이블` where (code1 like '%{$_POST['s']}%') ";
//echo $sql;
$qry = sql_query($sql);
while($row = sql_fetch_array($qry)) {
$code1 = $row['code1'];
$code2 = $row['code2'];
?>
<div><a href="#" onclick="copy('<?php echo $code; ?>','<?php echo $univ; ?>')"><?php echo "[{$code1}] {$code2}"; ?></a></div>
<?php
}
} else {
echo "<div style=\"text-align:center; height:100px; font-size:12px; padding-top:20px;\">검색하지 않았거나, 검색결과가 없습니다.</div>";
}
?>
</div>
</div>
</body>
</html>
< 예제. 2 >
1. 부모창
<script>
function openChild(url, field) {
var opt = "toolbar=no, resizable=yes, scrollbars=yes, location=no, resize=no,menubar=no, directories=no, copyhistory=0, width=400, height=200, top=100, left=100";
window.name = "ori_window";
window.open(url, 'new_window', opt);
}
</script>
<input type="radio" name="order_type" value="free">
초대코드인증 : <input type="text" name="free_num" id="free_num" style="width:100px;" readonly>
<input style="padding:2px 20px; height:24px;" onclick="openChild('search.php', this);" type="button" value="코드검색"><br>
2. 자식창 search.php
<?php
//include_once "_common.php";
$mysql_host = "localhost";
$mysql_user = "아이디";
$mysql_password = "비밀번호";
$mysql_db = "데이타베이스";
$dbconn = mysqli_connect($mysql_host,$mysql_user,$mysql_password,$mysql_db);
//$dbconn = mysqli_connect(G5_MYSQL_HOST,G5_MYSQL_USER,G5_MYSQL_PASSWORD,G5_MYSQL_DB); // 그누보드5
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>무료코드 검색</title>
<script language="javascript">
function ok() {
if (document.code.free.value=="" ) {
alert("\ 인증할 번호를 입력하여 주시기바립니다.");
return;
}
document.code.submit();
}
function InStrData(free_num){
opener.document.form.free_num.value = free_num;
window.close();
}
</script>
<style>
* {-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;}
a{text-decoration:none;}
th, td { font-size:12px; height:30px; }
</style>
</head>
<body>
<form name="code" method="post" action="search.php">
<div>
<img src="img/freecode_01.gif" width="9" height="33" align="absmiddle">
<strong>무료 코드번호</strong>
</div>
<div style="text-align:center; height:50px;">무료 코드번호
<input name="free" type="text" size="20" value="<?php echo $_POST['free']; ?>">
<input type="button" class="input_box" value="인증하기" onClick="ok()">
</div>
<div style="height:90px;">
<?php
if ($_POST['free']) {
$sql="select * from `디비테이블`_free where freecode='{$_POST['free']}'";
//echo $sql;
$qry = mysqli_query($dbconn,$sql);
$row = mysqli_fetch_array($qry);
if (!$row['freecode']) {
echo "입력하신 <strong>{$free}</strong> 의 번호가 올바르지 않습니다.<br>";
} else {
$freecode = $row['freecode'];
$wdate = $row['wdate'];
if ($row['wdate']) {
echo "입력하신 <strong>{$free}</strong> 는 {$row['wdate']}에 등록된 번호입니다.";
} else {
?>
<strong><?php echo $freecode; ?></strong> 인증되었습니다.<br>
사용된 코드는 등록완료후 재신청이 불가합니다.<br>
[ <a href="javascript:InStrData('<?php echo $freecode; ?>')"><strong>사용하기</strong></a> ]
<?php
}
}
}
?>
</div>
<div height="15" bgcolor="#F0F0F0"><center><a href='#' onClick='javascript:window.close();'>창닫기</a></center></div>
</form>
</body>
</html>
댓글목록
등록된 댓글이 없습니다.