Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2005, 02:29 PM
Registered User
 
Join Date: Aug 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default can you get window.opener data in server side code

i am building a sql statement that is executed at the beginning of the page, and this page is a popup. I want to be able to use some of the values from window.opener.whateverfields in the building of the sql statement. can I even do this?? I'm having a heck of a time here....thanks!

 
Old August 25th, 2005, 06:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

you certinaly can if you can pass them to the server side in either the Query String of the Form post submission.
 
Old August 26th, 2005, 08:15 AM
Registered User
 
Join Date: Aug 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that's what i was afraid of. the popup window is from a window.open call....I am passing some info in the querystring, but I have a rather large text field that I don't want to have to try and send in the querystring. It would be too much to hope for to be able to use window.opener.getelementbyid("something").value in the server side script, wouldn't it!

 
Old August 27th, 2005, 03:41 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

How could the server possibly know what a client is doing?
When you open the popup you ust need to pass the required values, as Greg suggested, via the POST or GET method. You then read these server-side and build your SQL (or use a stored procedure which is far safer).
A simple example, on the main page:
Code:
function openPopup()
{
  //Get the surname from the textbox
  var sSurname = document.getElementById("txtSurname").value;
  //Encode surname in case of non ASCII characters
  sSurname = encodeURIComponent(sSurname);
  //Build the URL to the popup
  var sUrl = "myPopupPage.htm?Surname=" + sSurname;
  var oWin = window.open(sUrl);
}
Then server-side, assuming ASP and SQL Server or such:
Code:
<%
  var sSurname = Request.Querystring.item("Surname") + "";
  //In real life use Adodb.command etc with stored proc
  //to avoid SQL injection and single quote problems etc.
  var sSql = "Select * FROM tblCustomer WHERE Surname = '"
           + sSurname + "'" 
  //Execute SQL and show results
%>
--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Converting Client-side to Server-side Code kwilliams ASP.NET 2.0 Professional 1 November 21st, 2007 05:25 PM
callback data to server side code aranjan ASP.NET 2.0 Basics 1 September 4th, 2007 06:39 AM
Problem accessing the window.opener.opener maryuob Javascript 3 January 18th, 2006 05:25 AM
Accessing Server Side Data on Client Side steve456 Classic ASP Professional 3 October 15th, 2003 02:33 PM
How to post data to window opener wjenkins Javascript How-To 4 August 30th, 2003 03:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.