弹出窗口值未反映在父窗口中

时间:2016-08-26 07:14:11

标签: javascript jsp

我试图在父窗口的文本框中获取弹出窗口的值。但它没有奏效。任何人都可以帮忙吗?

Parent.jsp

<style>
 a:hover, a:active {
   background-color:red ;
 }
</style>

<form action="FirstTest" method="post" id="TestForm">
   <input type="text" id="PrintHere"/ ><br><br>
   <a   target="_blank" onclick="SelectName('POST')"> Repository Link </a>
</form>

<script type="text/javascript">
  function SelectName(methodType) { 
    var win=window.open("Popup.jsp", "thePopUp", "width=300,height=100, left=24, top=24, scrollbars, resizable");
    win.focus();           
}
</script>

Popup.jsp

<form id="PopUpForm">
    <input type="text" id="ddlNames"> <br /> <br />
    <input type="button" value="Select" onclick="SetName();" />
</form>

<script type="text/javascript">
 function SetName() {
    if ((window.opener != null) && !(window.opener.closed)) {

    var Textvalue;
        Textvalue.value = document.getElementById("ddlNames").value;

        var TextBox = window.opener.document.getElementById("PrintHere");
        TextBox.value = Textvalue.value
    }
    window.close();
}     </script>

1 个答案:

答案 0 :(得分:0)

在Popup.jsp

上更改下面的代码
<form id="PopUpForm">
    <input type="text" id="ddlNames"> <br /> <br />
    <input type="button" value="Select" onclick="SetName();" />
</form>

<script type="text/javascript">
 function SetName() {
    if ((window.opener != null) && !(window.opener.closed)) {

        var TextBox = window.opener.document.getElementById("PrintHere");
        TextBox.value = document.getElementById("ddlNames").value;
    }
    window.close();
}     
</script>