By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,706 Members | 1,298 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,706 IT Pros & Developers. It's quick & easy.

opening a new window

P: 11
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


Expand|Select|Wrap|Line Numbers
  1. <tr> 
  2. <td colSpan="5"><strong><font face="Arial" size="2">Search Criteria:</strong></td>
  3.  
  4. <td><input type="text" name="GSearch" </font></strong></td>
  5.  
  6. <td colSpan="20">
  7. <INPUT TYPE="RADIO" NAME="DB" VALUE="1" CHECKED>Suppliers
  8. </p>
  9.  
  10. <INPUT TYPE="RADIO" NAME="DB" VALUE="2" >Members 
  11. </td>
  12.  
  13. <td>
  14. <td colSpan="10"><input type="submit" name="submit" value="Submit" align="right" onClick="window.open
  15. ('Search Results.asp','mywindow','width=600,height=400')">
  16. </td>
  17. </tr>
thanks
Feb 7 '07 #1
Share this Question
Share on Google+
12 Replies

acoder
Expert Mod 15k+
P: 16,027
Add an id for your text box, then pass it with the url in the new window:
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="GSearch" id="GSearch">
Expand|Select|Wrap|Line Numbers
  1. <input type="submit" name="submit" value="Submit" align="right" onClick="window.open
  2. ('Search Results.asp?Search='+document.getElementById('GSearch').value,'mywindow','width=600,height=400')">
  3.  
Then in your searchresults page, just process the GET variable (you know how to do that in ASP, I assume).
Feb 7 '07 #2

P: 11
Ive looked into this- but again i dont know. could you help me out?? Is is get function in asp or javascript???
Feb 7 '07 #3

acoder
Expert Mod 15k+
P: 16,027
The way I have described above, you should know ASP to deal with the variable. AFAIK, for a GET variable, you need to use the following:
Expand|Select|Wrap|Line Numbers
  1. Request.QueryString("GSearch")
Another way is to use Javascript in your ASP page, which uses window.opener:
Expand|Select|Wrap|Line Numbers
  1. window.opener.document.getElementById('GSearch').value;
would be a reference to your text box value in the popup window.
Feb 7 '07 #4

P: 11
Ive tried both and they arent working- however when i use
Expand|Select|Wrap|Line Numbers
  1. Response.Write(Request.QueryString)
it works?? But 1 problem with this is the fact that it displays Search= along with the result. Any ideas on how to get rid of this???
Feb 7 '07 #5

acoder
Expert Mod 15k+
P: 16,027
Use
Expand|Select|Wrap|Line Numbers
  1. Response.Write(Request.QueryString("Search"))
instead.
Feb 7 '07 #6

P: 11
thanks that is working- but 1 small point is how would i be able to pass more than 2 variables across using

Expand|Select|Wrap|Line Numbers
  1. <input type="submit" name="submit" value="Submit" align="right" onClick="window.open
  2. ('Search Results.asp?Search='+document.getElementById('GSearch').value,'mywindow','width=600,height=600')">
Feb 12 '07 #7

acoder
Expert Mod 15k+
P: 16,027
Use '&'+your search value pair, e.g.
Expand|Select|Wrap|Line Numbers
  1. onClick="window.open
  2. ('SearchResults.asp?Search='+document.getElementById('GSearch').value+'&myVal='+document.getElementById('SomeVal').value,...
Feb 12 '07 #8

P: 11
well ive tried that way and it doesnt seem to be working.
What Im actually doing is trying to pass the value of a radio buttons either 1 or 2 across- along with the text. The text works fine but not the passing of the radio- heres how my original page code looks like-

Expand|Select|Wrap|Line Numbers
  1. <tr> 
  2. <td colSpan="5"><strong><font face="Arial" size="2">Search Criteria:</strong></td>
  3.  
  4. <td><input type="text" name="GSearch" id="GSearch"></font></strong></td>
  5.  
  6. <td colSpan="20">
  7. <INPUT TYPE="RADIO" NAME="DB" VALUE="1" CHECKED>Suppliers
  8. </p>
  9.  
  10. <INPUT TYPE="RADIO" NAME="DB" VALUE="2" >Members 
  11. </td>
  12.  
  13.  
  14. <td>
  15. <input type="submit" name="submit" value="Submit" align="right" onClick="window.open ('Search Results.asp Search='+document.getElementById('GSearch').value+'&DB1='+document.getElementById('DB').value, 'mywindow','width=600,height=600')">
  16. </td>


And on my pop-up page- this is how I am requesting this:-

Expand|Select|Wrap|Line Numbers
  1. dim B
  2. B=Request.Form("DB")
  3.  
  4. if B=1 then 
  5. Response.Write("1")
  6.  
  7. else
  8. Response.Write("2")
  9. end if
  10.  
  11. H = (Request.QueryString("Search") & "<BR>")
Feb 14 '07 #9

acoder
Expert Mod 15k+
P: 16,027
Two points:

To use getElementById, you must set an id for the radio buttons.

Secondly, you're passing parameter DB1, not DB, so in your popup, you should check for DB1.
Feb 14 '07 #10

P: 11
there is abit of a problem, ive done what u said- however- when im selecting either radio button it only send the value 1. Whether i select the first radio button or the second it only passed the value 1???

Heres my input button code:-

Expand|Select|Wrap|Line Numbers
  1. <table border="1" width="100%" bgColor="#3380b2" border="0" cellSpacing="2" cellPadding="2">
  2. <tr> 
  3.     <td colSpan="5"><strong><font face="Arial" size="2">Search Criteria:</strong></td>
  4.  
  5.     <td><input type="text" name="GSearch" id="GSearch"></font></strong></td>
  6.  
  7.     <td colSpan="20"><INPUT TYPE="RADIO" NAME="DB1" id="DB1" VALUE="1" CHECKED>Suppliers</td>      
  8.     </p>          
  9.     <td colSpan="20"><INPUT TYPE="RADIO" NAME="DB1" id="DB1" VALUE="2">Members</td>
  10.  
  11.  
  12.  
  13. <td>
  14.  
  15. <input type="submit" name="submit" value="Submit" align="right" onClick="window.open
  16. ('Search Results.asp?Search='+document.getElementById('GSearch').value+'&DB1='+document.getElementById('DB1').value, 'mywindow','width=600,height=600')">
  17.  
  18. </td>


And heres how i am requesting this

Expand|Select|Wrap|Line Numbers
  1. H = (Request.QueryString("Search"))
  2. B = (Request.QueryString("DB1"))
If it also helps- ive also looked at this way of requeting my radio buttons:-

Expand|Select|Wrap|Line Numbers
  1. B= Request.Form("DB")
  2.  
  3. if B="1" then 
  4. Response.Write("1")
  5.  
  6. else
  7. Response.Write("2")
  8. end if
However it Is not working- this time it only prints out 2 even though ive selected the first radio button- the the exact opposite of the first problem- not sure why?

Any suggestions??
Feb 14 '07 #11

P: 11
Ive got it sorted - thanks to all- all i did was create a script and feed all the information to the script so that it opens the link from the script which enabled me to send the info to the next page
Feb 14 '07 #12

acoder
Expert Mod 15k+
P: 16,027
Ive got it sorted - thanks to all- all i did was create a script and feed all the information to the script so that it opens the link from the script which enabled me to send the info to the next page
Glad you got it sorted. I was about to suggest that you set the target of your form to the new open window and let the GET method pass the values automatically, but you got it working anyway. The Javascript method of getting the selected value from a radio button requires looping through the radio buttons.
Feb 14 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.