php - Cannot retrieve text box value in java script popup -
i want pass text box value in parent.php popup window(child_page.php). following code. 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
<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 textbox value here. ?>
i googled , tried it. since know little java script couldn't pull answers solution.
there many errors in html. writing input element before closing head tag. move inside body. , try 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 child_page.php
can value using $_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; ?>
Comments
Post a Comment