opening a new window

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • new214
    New Member
    • Dec 2006
    • 11

    opening 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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Add an id for your text box, then pass it with the url in the new window:
    Code:
    <input type="text" name="GSearch" id="GSearch">
    Code:
    <input type="submit" name="submit" value="Submit" align="right" onClick="window.open
    ('Search Results.asp?Search='+document.getElementById('GSearch').value,'mywindow','width=600,height=400')">
    Then in your searchresults page, just process the GET variable (you know how to do that in ASP, I assume).

    Comment

    • new214
      New Member
      • Dec 2006
      • 11

      #3
      Ive looked into this- but again i dont know. could you help me out?? Is is get function in asp or javascript???

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        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:
        Code:
        Request.QueryString("GSearch")
        Another way is to use Javascript in your ASP page, which uses window.opener:
        Code:
        window.opener.document.getElementById('GSearch').value;
        would be a reference to your text box value in the popup window.

        Comment

        • new214
          New Member
          • Dec 2006
          • 11

          #5
          Ive tried both and they arent working- however when i use
          Code:
          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???

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Use
            Code:
            Response.Write(Request.QueryString("Search"))
            instead.

            Comment

            • new214
              New Member
              • Dec 2006
              • 11

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

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

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Use '&'+your search value pair, e.g.
                Code:
                onClick="window.open
                ('SearchResults.asp?Search='+document.getElementById('GSearch').value+'&myVal='+document.getElementById('SomeVal').value,...

                Comment

                • new214
                  New Member
                  • Dec 2006
                  • 11

                  #9
                  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-

                  Code:
                  <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" VALUE="1" CHECKED>Suppliers
                  </p>
                  				  
                  <INPUT TYPE="RADIO" NAME="DB" VALUE="2" >Members 
                  </td>
                  
                   				  
                  <td>
                  <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')">
                  </td>


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

                  Code:
                  dim B
                  B=Request.Form("DB")
                  
                  if B=1 then 
                  Response.Write("1")
                  
                  else
                  Response.Write("2")
                  end if
                  
                  H = (Request.QueryString("Search") & "<BR>")

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    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.

                    Comment

                    • new214
                      New Member
                      • Dec 2006
                      • 11

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

                      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="DB1" id="DB1" VALUE="1" CHECKED>Suppliers</td>	  
                      	</p>		  
                      	<td colSpan="20"><INPUT TYPE="RADIO" NAME="DB1" 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('GSearch').value+'&DB1='+document.getElementById('DB1').value, 'mywindow','width=600,height=600')">
                      
                      </td>


                      And heres how i am requesting this

                      Code:
                      H = (Request.QueryString("Search"))
                      B = (Request.QueryString("DB1"))
                      If it also helps- ive also looked at this way of requeting my radio buttons:-

                      Code:
                      B= Request.Form("DB")
                      
                      if B="1" then 
                      Response.Write("1")
                      
                      else
                      Response.Write("2")
                      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??

                      Comment

                      • new214
                        New Member
                        • Dec 2006
                        • 11

                        #12
                        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

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          Originally posted by new214
                          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.

                          Comment

                          Working...