...

View Full Version : opening up a new window



new214
02-07-2007, 12:07 PM
Heya all, I want to know how to pass a variable across when opening a new window using javascript.
Ive got a text field and a button-and by changing properties of the button i can get it to open up a new window- however i want to know how i can pass the text field value so it appears in my pop-up window

Heres my code- im using asp


<tr>
<td colSpan="5"><strong><font face="Arial" size="2">Search Criteria:</strong></td>

<td><input type="text" name="GSearch" </font></strong></td>

<td colSpan="20">
<INPUT TYPE="RADIO" NAME="DB" VALUE="1" CHECKED>Suppliers
</p>

<INPUT TYPE="RADIO" NAME="DB" VALUE="2" >Members
</td>

<td>
<td colSpan="10"><input type="submit" name="submit" value="Submit" align="right" onClick="window.open
('Search Results.asp','mywindow','width=600,height=400')">
</td>
</tr>

thanks:thumbsup: :cool: :) :rolleyes:

Pyth007
02-09-2007, 01:06 AM
Phew! Where to begin?

I can think of several ways to accomplish what you're asking for. I'd first suggest that you look up a tutorial on Window objects and javascript (like this (http://www.wsabstract.com/javatutors/window1.shtml)) to get more familiar with how window objects operate.

Basically, child windows can be assigned to a variable when they are opened, and then the parent can use that variable to act upon the child:


var myWindow = window.open("mysite.com", "WindowName", "<options here>");
myWindow.document.bgcolor=green;


The child window also has the key-word 'opener' that can be used to refer to the parent:


window.onload = function() { document.getElementById('myText').value = window.opener.document.getElementsByName('GSearch')[0].value;}


Also, because this is calling an ASP-page which is going back to the server (probably to run the search), you may want to append the value at the end of the URL to make it a GET parameter:


<input type="submit" name="submit" value="Submit" align="right" onClick="window.open
('Search Results.asp'+(document.getElementsByName('GSearch')[0].value?'?term='+document.getElementsByName('GSearch')[0].value:''),'mywindow','width=600,height=400')">


Note that I havn't tried any of these, so don't know how well they'll work... their just meant to give you an idea of the options out there. Also I've been using getElementsByName() function a lot because your textbox only has a name; however, this function is not being used correctly (unless your whole structure is inside a form). I'd suggest using an id in addition to the name and then using the getElementById() DOM-function instead.

One other note... If this is a form, your onclick function may be opening two pages: one from the window.open javascript and the second from the HTML form (ie if this is inside a form, the submit button will submit the form as well as execute the onclick function). If this was your intent, then nothing different needs to be done. However, if you were planning to have the popup-window as the only window that gets opened, you may need to incorporate the onclick stuff as the form's onsubmit function and then 'return false;' to prevent the form from being submitted as well. This is what web-designers consider to be 'degrading gracefully'. For users that implement javascript, they would get the popup window as a "feature" to your site that acts in place of an actual form submittion. But because not all web-users will have javascript turned on, you'd have a form that gets submitted in the regular HTML way (ie the onsubmit function would not be run, so no popup window, but no 'return false;' either so the form gets submitted).

Finally... depending on what you are planning to do, you may consider using a <div> that is "absolutely positioned" on top of the current page (using the z-index style) to house your results (and perhaps an AJAX call to the server via an ASP page to get those results). This would eliminate a few other problems you may run into: 1) entire page-loads use a lot of memory / bandwidth whereas AJAX would only spit back the specific data received from the search and 2) many users have popup blockers turned on, so you'd have to encourage users to turn them off when using your site.

new214
02-14-2007, 02:22 PM
Thanks for the help- but ive tried that way which isnt working. Actually- i would rather use my own code as ive spent time on it already.

Im trying to pass a text box value along with a value from a radio button across to a pop-up window using javascript.

I can successfuly open up a new window and pass the value of the textbox to the other window- but not the radio button.

Heres my code for the orignal page consiting of a text box, radio button and submit button:-


<table border="1" width="100%" bgColor="#3380b2" border="0" cellSpacing="2" cellPadding="2">
<tr>

<td colSpan="5"><strong><font face="Arial" size="2">Search Criteria:</strong></td>

<td><input type="text" name="GSearch" id="GSearch"></font></strong></td>

<td colSpan="20"><INPUT TYPE="RADIO" NAME="DB" id="DB1" VALUE="1" CHECKED>Suppliers
<P>
<INPUT TYPE="RADIO" NAME="DB" id="DB1" VALUE="2">Members
</td>

<td>
<input type="submit" name="submit" value="Submit" align="right" onClick="window.open
('Search Results.asp?Search='+document.getElementById('GSea rch').value+'&DB1='+document.getElementById('DB').value, 'mywindow','width=600,height=600')">
</td>

And in my pop-up window im trying to request the text box and radio button values as:-


Dim H
H = (Request.QueryString("Search"))


Dim B as string
B = Request.QueryString("DB1")

But the radio button value isnt working????
ANY Suggestions on this?? Ive also tried the following way:-
But again to not luck




B = Request.Form("DB1")



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum