Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    opening up a new window

    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

    Code:
    <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

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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) 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:
    Code:
    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:
    Code:
    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:
    Code:
    <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.
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!

  • #3
    New Coder
    Join Date
    Nov 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    opening up a new window

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

    Code:
    <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:-

    Code:
    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


    Code:
    B = Request.Form("DB1")


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •