아이프레임 (iframe) 으로 폼값 넘기기
페이지 정보
작성자 서방님 댓글 0건 조회 353회 작성일 11-11-02 11:14본문
<script language="javascript">
function a() {
frm.method ="post";
frm.action = "b.jsp";
frm.target = "a";
frm.submit();
}
</script>
<form name="frm">
<input type="text" class="box05" value="" size="18" maxlength=20 name="Contents">
<a href="javascript:a(">click</a>
<br />
<br />
</form>
<iframe frameborder="1" width="540" src="a.jsp" name="a" scrolling="no" frameborder="0" width="645" height="320"></iframe>
========================================================
폼의 내용을 전송하여 클릭할 때마다 같은 페이지 내에서 반복적으로 변화시켜줘야 하는 경우가 있다. 이런 경우 javascript의 innerHTML이나 아예 Ajax를 이용할 수도 있지만, DB와 연동시키기 위해서는 form과 iframe을 이용하는 것이 편할 수 있다.
이 때 주의할 점은 iframe의 name을 지정해야 한다는 점이다. (id를 지정하면 안된다)
<form action="./action.php" method=post target="ifr">
<input type=text name="a" />
<input type=submit />
</form>
<iframe name="ifr" src="./page2.php"></iframe>
//page2.php의 내용
<?=$_POST[a]?> 라고 입력하셨군용~
========================================================
<script language="javascript">
<!--
function icon_popUp(gubun, num, flags) {
var para = document.URL.split('?');
var qString = (para.length > 1) ? escape(para[para.length - 1]) : "";
pFrame.location.replace("http://www.xxx.xx.xx/search/icon_process.php?gubun=" + gubun + "&num=" + num + "&flags=" + flags + "&qString=" + qString);
}
-->
</script>
<!--<form name="voteform"></form>//-->
<iframe name="pFrame" width="0" height="0" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
========================================================
1. a.html
<html>
<head>
<title>로그인 </title>
</head>
<script language="javascript">
function send_c()
{
alert("11");
alert(iframeb.b.b_val.value);
alert("22");
alert(iframec.c.c_val.value);
iframec.c.c_val.value = iframeb.b.b_val.value;
document.location = a.html;
}
</script>
<body>
a.html안의 iframe에 b.html, c.html이 있다.<br>
<iframe name="iframeb" src="b.html" border=1 height=100 width=300 ></iframe>
->
<iframe name="iframec" src="c.html" border=1 height=100 width=300></iframe>
<a href="javascript:send_c();">확인 </a>
</body>
</html>
2. b.html
<html>
<head>
<title>로그인 </title>
</head>
<body>
요기는 b.html
<form name="b" method="post" >
과일이름 : <input type=text name=b_val value="사과" > <br>
</form>
</body>
</html>
3. c.html
<html>
<head>
<title>로그인 </title>
</head>
<body>
<form name=c>
요기는 c.html
<input type=text name=c_val value="">
</form>
</body>
</html>
댓글목록
등록된 댓글이 없습니다.