最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how to pass value to pop up window using javascript function? - Stack Overflow

programmeradmin10浏览0评论

I want to open new window from existing form.When I am clicking on new window in form then new form should open with results of value entered,but new window form is opening with main page,not able to get text box value from parent form.

How to call textfield input value in popup window from parent window using javascript?

//currently I'm using following code:
<script type="text/javascript">
function pop_up5() {
  var l_url=window.opener.document.getElementById("name").value;
  window.open(l_url,'''','scrollbars=yes,resizable=no,width=550,height=400');
}
</script>

I want to open new window from existing form.When I am clicking on new window in form then new form should open with results of value entered,but new window form is opening with main page,not able to get text box value from parent form.

How to call textfield input value in popup window from parent window using javascript?

//currently I'm using following code:
<script type="text/javascript">
function pop_up5() {
  var l_url=window.opener.document.getElementById("name").value;
  window.open(l_url,'''','scrollbars=yes,resizable=no,width=550,height=400');
}
</script>
Share Improve this question edited Dec 20, 2012 at 7:24 Jan Hančič 53.9k17 gold badges98 silver badges101 bronze badges asked Dec 20, 2012 at 7:20 varadarajvaradaraj 31 gold badge1 silver badge6 bronze badges 1
  • 1 Have you tried passing querystring fields..? – Anujith Commented Dec 20, 2012 at 7:27
Add a ment  | 

2 Answers 2

Reset to default 2

Assign window.open() to a variable so you can access it's elements.

<form>
    <input type="textbox" id="txt" />
    <input type="button" id="btn" value="Open window" />
</form>

<script>
document.getElementById('btn').onclick = function(){
    var myWindow = window.open();
    myWindow.document.body.innerHTML = document.getElementById('txt').value;
};
</script>

Suppose your text field's id is myTextField, whatever you named it. if it has no id, set a id for it. then, in the popup window, you can use JavaScript parent.document.getElementById('myTextField').value to get the value of the textfield.

发布评论

评论列表(0)

  1. 暂无评论