JavaScript - How Do You Post A Variable To A Pop-up Window?
I can't seem to figure out how to post a variable to a javascript pop-up window. I'm trying to get a the users input to post directly to the URL.
For example: Code: <!--Pop-up--> <script type="text/javascript"> <!-- function expo() { window.open( "export.php?&export=<?PHP $myvar = $_POST['exportthis']; echo $myvar; ?>", "myWindow", "status = 1, height = 300, width = 300, resizable = 0" ) } //--> </script> <form action="" method="post"><input type=text value="pass-this-variable" name="exportthis"> <input type=button value="Export" name="Exp" onClick="expo()"> </form> Any suggestions? Similar TutorialsCode: <fieldset class="submit" style="padding-left: 200px;"> <?php if ($site_exist >= 1){ echo "<input type=\"submit\" name=\"submit\" value=\"Update\">"; } else { echo "<input type=\"submit\" name=\"submit\" value=\"Submit\">";} ?> <!-- This is the button I am having trouble with. --> <input type="button" name="delete" value="Delete" onClick="return confirmSubmit()"> </fieldset> </form> <script type="text/javascript"><!-- function confirmSubmit(){ var agree=confirm("Are you want to delete this site from our index?"); if (agree) return true ; else return false ; } // --> </script> Not entirely sure which forum this should go in, since the problem could probably be fixed with HTML, PHP or Javascript. Anyway, I have the confirmation window working. What I need is for the button to post a variable (siteDelete = 'true') when it is pressed. I would prefer to do that part without javascript, but I want the data to be posted after and only after the confirmation window returns true. I can do that with a submit button, but I'm not sure what code to use and where to use it when using a non-submit button. How can I send POST variables to a new window on form submit. I tried the below but what happens is the new window "foo.php" opens but no POST variables are present and also the parent page refreshes when I want it to remain static. Code: <form method="POST" onsubmit="return validateForm(this) && transferListValuesToCSV(document.theForm.box2) && window.open('foo.php', 'foo', 'width=450,height=300,status=yes,resizable=no,scrollbars=no')"; name="theForm" > Situation: adding code to an HTML page that I can add to, but not change any existing code, as it is from a vendor and gets generated on the fly. I need to add a button within the existing <form></form> construct that already has a submit button and the form has an "action=" in it. What I have done is added <input type=button onClick=myscript().... Myscript() opens a .php file as a popup, positions it correctly, and all that. What it doesn't do is move the values to the .php like a method=POST would. Is there anyway to to do this, or do I have to do a set of document.write statements? Existing code: Code: <!-- vendor's untouchable code --> <form method=post name="MainForm" action="xxx.asp?yyy" onsubmit="the_vendors_code();> <input type="text" name="fielda" value="" > <!-- several more fields --> <!-- my code --> <SCRIPT type="text/javascript" SRC="xxx.js"></SCRIPT> <SCRIPT type="text/javascript"> function popupForm(myForm, windowName) { var scrny=0 ; var scrnx=200 <-! code to set scrny and scrnx based on browser --> fielda_h.value = fielda.value ; <!-- etc ..> <!-- here's the place I need help --> newWin= window.open("myPopup.php", windowName, 'height=600,width=550,and a whole bunch of other parameters') ; newWin.moveTo(scrnx, scrny) ; myForm.rel="nofollow" target=windowName; return true ; } </script> <input type="hidden" name="fielda_h" > <input type="button" name="preview" value="See Preview" onClick="popupForm(this, 'join')"/> Note that some of the code was taken from examples found on the net, so there's not a ton of originality here. So, again, just to restate, I know how to do a submit button/form to do action=post, but I am trying to simulate it with a regular button as I cannot change the existing <form></form> construct. Thanks for any and all pointers. Hi guys, hoping you can help me out again, with this new problem. I've got a form which is acting as a calculator. Once the calculation is complete I want it so when the user presses a 'print' button it takes certain parts of the form data and displays them in a new window which would be designed for printing. how can i go about this using only javascript? thanks Hi friends, i'm using greybox on my website, and using survey. i want when click submit button then post form data to opened greybox window.. but can't.... my form actions <form action="anket.php?islem=ok" method="post" onSubmit="javascript:return GB_showCenter('Anket',this.action, 280, 350)" > greybox window open, but can't show post data.. can anyone help me ? sorry for may bad english I having trouble with this code, I have this timer running in a js file if the timer runs out then an alert box pops up letting the user know that they have been logged out. There is also a pop-up window and if the user press down on the key board then the timer resets. I have already done this in my test files, What I am trying to do is apply it to this other code and its a bit tricky. Below you will find my test code. test1.php PHP Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" language="javascript"> var test2 function popup() { test2=window.open( "test2.php", "myWindow", "status = 1, height = 300, width = 300, resizable = 0" ) } </script> </head> <body> <?php echo '<a href="#" onclick="popup()" >Click Here</a>'; echo '<embed src="logout_operator.wav" autostart="false" id="logout" width="0" height="1" loop="false">'; echo '<script type="text/javascript" language="javascript" src="test.js"></script>'; echo '<script type="text/javascript" language="javascript"> function timeout(logoutSound) { var soundLogout=document.getElementById(logoutSound); soundLogout.Play(); alert("Your session is expired please login again"); location = "http://www.google.com"; } </script>'; ?> </body> </html> test2.php (pop-up window) PHP Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" language="javascript" src="test.js"></script> </head> <body> <script type="text/javascript" language="javascript"> window.onkeydown = handle; function handle() { resetTimer(); return true; } </script> </body> </html> test.js Code: var timer = setTimeout("timeout('logout')", 5000); function resetTimer(d) { clearTimeout(timer); if (d!="done"){ if (location.href.indexOf("test2.php")!=-1){ window.opener.window.resetTimer("done"); } else{ test2.window.resetTimer("done"); } } timer = setTimeout("timeout('logout')", 5000); } What I am trying to do is apply the function and the button to this code: Code: var _h = { mi: function (link, title, ni, qi, width, height, ri) { return '<a href="' + link + '"' + (ri != null ? ' class="' + ri + '"' : '') + ' target="_blank" title="' + title + '" onclick="this.newWindow = window.open(\'' + link + '\', \'' + ni + '\', \'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=' + width + ',height=' + height + ',resizable=1\');this.newWindow.focus();this.newWindow.opener=window;return false;">' + qi + '</a>'; } I have tried to put the test2 variable as _h but that didn't work at all. Any help would be much appreciated, thanks!!! Hi there, i have one script which is supposed to pop up a new win and after it does write a piece of text in it. This text comes from inside the HTML area: Code: (script) function popupwin(whichOne) { var width = 450; var height = 490; var left = parseInt((screen.availWidth/2) - (width/2)); var top = parseInt((screen.availHeight/2) - (height/2)); var windowFeatures = "width=" + width + ",height=" + height + ",status=no,resizable=no,location=no,titlebar=no,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top; newwin = window.open("spSelect.html","spSelect",windowFeatures); spSelect.document.whichOne.value = whichOne; } (calling part in html) <a href="javascript: popupwin(Souvlaki);"><img src="images/orderbutton.gif" width="100" height="20" border="0"></a> (new win place where text is supposed to appear) <input name="whichOne" readonly="readonly" type="text" class="textfield"> Hello folks, I have a very simple problem...but stuggling with this. I have a popup window (.aspx page). It will called from a parent .aspx page. All I want to do is read the name of the parent aspx page in popup page. Based on the name of the parent window, in the page_load event of the popup window, I want to execute some code. But the only catch is that, I am not able to read the parent window name until the page_load event (of popup window) complets the execution. 1. calling popup window from parent window. Code: Code: function OpenWindow_HistoricalRuns() { var windowIncsimHistRuns = window.open('MVal.aspx', 'Market', 'width=350,height=425,scrollbars=0'); windowIncsimHistRuns.moveTo(500, 300); } In the body of the popup window the following function tries to read the parent window name: Code: function SetDisplay() { document.getElementById('<%=TextBoxSourcePageName.ClientID%>').value = window.parent.name; } In the page_load event of the popup window, I want to see what is value of TextBoxSourcePageName control. I hoped I will get 'MarketVal'. But I never get anything. Code: protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { try { if (TextBoxSourcePageName.Text == "MarketVal") } } } In my situation, I need to know the window.parent.name by the time Page_load event gets triggered on the popup window. Because I have to do some specific thing in the Page_Load event (of popup window), based on window.parent.name. So my fundamental question is, which one will get fired first in an .aspx page. 1. Javascript in the body tag or 2. Page_load event of the .aspx page. If Javascript function in the body tag gets fired first, then by the time I get to Page_Load event, I should already have whatever I need. thanks Sorry, this is a newbie question, and probably really dumb, but... If I create a function that looks like this... Code: function recall(tim) { setTimeout("window.location.replace('somepage.html')",tim); } ...it works fine when called. However; I want to be able to pass the page url in a variable, something like this... Code: function recall(tim, myurl) { setTimeout("window.location.replace(myurl)",tim); } ...but this creates an error, saying "myurl is not defined." Even if I simplify the code and place the url in a variable within the function... Code: function recall(tim) { var myurl="somepage.html"; setTimeout("window.location.replace(myurl)",tim); } ...I still get the "myurl is not defined" error, even tho I am defining it. Plz can someone explain what I'm doing wrong. Tkx... --paul Hey, I'm looking for a way to get a variable from a parent window in a child window. I'm aware that you can write the variable to a hidden field and then get the field's value in the child window, but I'm looking for a cleaner (all JS preferable) way of doing this. Something like this, but I believe this is an out-dated solution: Code: var str = window.opener.str; alert(str); Any solutions? On my main page, I have a list of item ID's which are assigned variables, the list is concatenated and so the variables are always different. So another thing that gets concatenated is a link, which uses javascript/jquery to open a popout modal window which is another php file called sharepost.php. I want to be able to transfer the php variables from the main page to append them on the end of the sharepost.php URL so I can use $_GET to grab them for use. Here's what I have... not working, but I figured I'd give it a try. Code: <?php //use mysql to loop through some variables $post_id = $setvalue; $member_id = $anothersetvalue; $list .= ' <div> ' . $post_id . ' </div> <div> ' . $member_id . ' </div> <div> <a href="#" class="button" onClick="openup(); return false">Share This Post</a> </div> $the_link = " http://sharepost.php?post_id=' . $post_id . '&member_id=' . $member_id . ' "; '; ?> <HTML> <head> <script> // Displays an external page using an iframe function openup(){ var src = "<?php echo $the_link;?>"; $.modal('<iframe src="' + src + '" height="450" width="830" style="border:0">', { closeHTML:"", containerCss:{ height:150, padding:0, width:350 }, overlayClose:true, }); } </script> </head> <body> <?php echo $list;?> </body> </HTML> i have this code i need to close the parent.html window when the child window opened, i need the code for that working well in IE and Firefox Parent.html <HTML> <SCRIPT TYPE="text/javascript"> function sendTo() { window.open('child.html','_blank','resizable=yes,width='+(screen.width-500)+',height='+(screen.height-500)+''); } </SCRIPT> <BODY > <form name="form"> <input type="text" value="" name="text1" id="pdetails1"> <input type="text" value="" name="text1" id="pdetails2"> </br> <input type="submit" value="submit" onClick="sendTo()"> </BODY> </HTML> child.html <html> <body> <form> <input type=text name="text5" value=""> <input type=submit name="submit"value="submit"> </form> </body> </html> Hello all, and thank you for your coments, I want to preserve a 16/9 aspect ratio to the window after any resize, making the width a function of the height. As I have a window.resizeTo() inside the window.onresize event function, the infinite loop is served. How may I quit it? Code: <html><head><title>Title</title><script languaje="javascript"> const c_ra=16/9; window.onresize = function WindowReSize() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE // myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' // myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } myWidth = Math.floor(myHeight*c_ra); window.resizeTo(myWidth,myHeight); // ** CAUTION resize event in a onresize event handler ! }; </script></head><body><p>Hello World</p></body></html> Here is the program: http://www.1728.com/newwindow.htm Basically, I want to input a number in the input box, which assigns a number to the variable numval located at document.box1.b1. When clicking on the "new window" button, an alert displays the input box value, then another window opens and displays the integers 1 through 12 and the amount squared. I would like the new window to obtain the number from the previous window so that the new window will display integers (and their squares) from 1 to the value of numval. hello everybody i need your help and experience for having code to show ( overlay / modal window ) to the user when closing or navigating away from the page ( i want put in this window facebook share to make the user to share the page in his facebook ) , bytheway i wanna use it in my wordpress in every post could it be happen ? Thanks for helping I have created and opened a child window called "checkwin" and have written some data to it. If the data is valid, I want the user to click on the 'CONFIRM' button on the child window, at which time I want the "submit()" function for the form on the parent window to be executed. If the data is invalid the user clicks on 'MODIFY' and I want focus to return to a field on the parent form. However, when I click on the "CONFIRM" or "MODIFY" buttons on the child window, nothing happens. Here is the code: Code: checkwin.document.write("</td></tr><tr><td align='right'><input type='button' value='CONFIRM' onclick='opener.document.personnel_form.submit()'></td><td></td><td><input type='button' value='MODIFY' onclick='opener.document.personnel_form.first_name.focus()'></td></tr></table>") I am looking to have a link open a closeable window that is contained within a browser window. If you click on the "sizing charts" link on this website, this is exactly what I am looking to do: http://www.bella.com/mapper.php?pageid=40 The window is contained within the current browser window, it can be dragged around, but not outside the parameters of the browser window. Is there a title for this technique that I can research? Not looking to waste anybodys time, but if I can get steered in the right direction it would be greatly appreciated. Thanks Hi All, I need to show/focus the parent window which is in back when click a link from child window in Chrome.This problem is in Chrome browser only. We have used the below code self.blur(); Window.opener.focus(); But this is not working in Google Chrome. Please suggest me some workaround to achieve this. Thanks in Advance Reply With Quote 12-19-2014, 09:26 PM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,311 Thanks 82 Thanked 4,754 Times in 4,716 Posts Window is not defined. window is. JavaScript (and the DOM) is case sensitive. You must pay attention to upper/lower case spelling, carefully. By the way, you shouldn't need the blur() call. If you focus on some window (any window) then any other focus should be lost. Hi Ive found out how to force another browser window to open at a certain size when a link is clicked. Here's the whole line of code including the layer, the javascript and the image, <div id="Layer6" style="position:absolute; width:10px; height:8px; z-index:6; left: 561px; top: 310px"><a href="javascript:;" onClick="MM_openBrWindow('navigation%20instructions.htm','','width=50,height=50')"><img src="images/info.gif" width="15" height="15" border="0"></a></div> How do I adapt this so I can also specify the x&y co-ordinates of the opened window relative to the window that launched it. thanks alot Masten |