[英]Cannot retrieve text box value in java script popup
I want to pass a text box value in parent.php to my popup window(child_page.php). 我想将parent.php中的文本框值传递到弹出窗口(child_page.php)。 Following is my code. 以下是我的代码。 parent.php- parent.php-
<html>
<head>
<script type="text/javascript">
var popupWindow=null;
function child_open()
{
popupWindow =window.open('child_page.php',"_blank","directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=600, height=280,top=200,left=200");
}
function parent_disable() {
if(popupWindow && !popupWindow.closed)
popupWindow.focus();
}
</script>
<input type="text" name="myTextField" id="myTextField" required="required"/>
</head>
<body onFocus="parent_disable();" onclick="parent_disable();">
<a href="javascript:child_open()">Click me</a>
</body>
</html>
child_page.php child_page.php
<h1>child page</h1>
<script>
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
var x=parent.document.getElementById('myTextField').value
<?php echo x; ?>
</script>
<?php
//how do I get the textbox value here.
?>
I googled it and tried to do it. 我用谷歌搜索并试图做到这一点。 Since I know little about java script couldn't pull those answers together as a solution. 由于我对Java脚本知之甚少,因此无法将这些答案作为解决方案。
There are many errors in your html. 您的html中有很多错误。 You are writing input element before closing head tag. 您正在关闭head标签之前编写输入元素。 Move it inside body. 将其移入体内。 And try something like this: 尝试这样的事情:
<html>
<head>
<script type="text/javascript">
var popupWindow=null;
function child_open(val){
popupWindow =window.open('child_page.php' + "?val=" + val,"_blank","directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=600, height=280,top=200,left=200");
}
function parent_disable() {
if(popupWindow && !popupWindow.closed)
popupWindow.focus();
}
</script>
</head>
<body onFocus="parent_disable();" onclick="parent_disable();">
<input type="text" name="myTextField" id="myTextField" required="required"/>
<a href="#" onclick="var val = document.getElementById('myTextField').value; child_open(val);return false">Click me</a>
</body>
</html>
Now in your child_page.php
you can get the value using $_GET['val']
. 现在,在child_page.php
您可以使用$_GET['val']
获得值。
//child_page.php
<h1>child page</h1>
<?php $x = $_GET['val']; ?>
<script>
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
</script>
<?php echo $x; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.