select from list in pop-up window and set value of text box in parent window

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mychikka
    New Member
    • Mar 2009
    • 21

    select from list in pop-up window and set value of text box in parent window

    How to's:

    I have java script that opens a new window now inside my pop-up window I have list of names display and I want to select the names and insert it on my PHP page text box. Anybody who can show me how to do this?

    thanks!

    Code:
    echo '
        <h2>' . ( $id ? translate ( 'Edit Entry' ) : translate ( 'Add Entry' ) )
     . $eType_label . '&nbsp;<img src="images/help.gif" alt="' . translate ( 'Help' )
     . '" class="help" onclick="window.open( \'search_contact.php'
     . ( empty ( $id ) ? '?add=1' : '' )
     . '\', \'cal_help\', \'dependent,menubar,scrollbars,height=400,width=800,'
     . 'innerHeight=420,outerWidth=420\' );" /></h2>'
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    There no Java in your question; where do you want me to move your question to? A Javascript forum or a PHP forum?

    kind regards,

    Jos (moderator)

    Comment

    • mychikka
      New Member
      • Mar 2009
      • 21

      #3
      Hi Josah,

      Originally I posted this thread on PHP but I was told by Markus to put this on JAVA forum.

      Basically after doing the pop-up window I just wanted to grab the variable selected to the other page. I hope I discribe the process I wanted to do well. Now Im looking for answer how to do this.

      thanks again

      Comment

      • mychikka
        New Member
        • Mar 2009
        • 21

        #4
        pop-up window var

        I have java script inside my php that opens a 2nd page window. What I wanted to do is to select the name (for example) from the pop-up window and send the value to my original page on PHP text box. Anybody who can show me how to do this?


        Code:
        echo '  
            <h2>' . ( $id ? translate ( 'Edit Entry' ) : translate ( 'Add Entry' ) )  
         . $eType_label . '&nbsp;<img src="images/help.gif" alt="' . translate ( 'Help' )  
         . '" class="help" onclick="window.open( \'search_contact.php'  
         . ( empty ( $id ) ? '?add=1' : '' )  
         . '\', \'cal_help\', \'dependent,menubar,scrollbars,height=400,width=800,'  
         . 'innerHeight=420,outerWidth=420\' );" /></h2>'

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          You want to send back the name from pop-up window to opener window.
          You should have a event handler on the pop-up window when you will send back the name to opener window. Access your opener document using "opener.documen t" in pop-up window JavaScript ;)
          That's what you wanted ?

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by mychikka
            Hi Josah,

            Originally I posted this thread on PHP but I was told by Markus to put this on JAVA forum.

            Basically after doing the pop-up window I just wanted to grab the variable selected to the other page. I hope I discribe the process I wanted to do well. Now Im looking for answer how to do this.

            thanks again
            Hi,

            it definitely isn't a Java question; there's a bit of Javascript in your file but you also mention PHP (on the server side?) It was a mistake to redirect you to this Java forum (there is no Java in the vicinity ;-)

            I'll move it to the Javscript forum; good luck.

            kind regards,

            Jos

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Once you have access to the opener window, to set the text box value:
              Code:
              opener.document.getElementById("textboxID").value = val;
              where "textboxID" is the ID of the text box and val is the value selected.

              Comment

              • mychikka
                New Member
                • Mar 2009
                • 21

                #8
                Here's what I got after encorporating acecoder's code but it doesn't do anything. By the way I put this script on the pop-up window or second window. Please let me know what im missing.

                Code:
                echo "<input type='button' value='Select' onclick=window.opener.document.getElementById( 'ContactID' ).value = value_from_contactbox  window.close()'>";

                Comment

                • mychikka
                  New Member
                  • Mar 2009
                  • 21

                  #9
                  or should I add any on the main page where it's calling the pop-up window?

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Two things:
                    1. is value_from_cont actbox set correctly by the time you click on the button?
                    2. You need a semi-colon after that statement before window.close().

                    Comment

                    • mychikka
                      New Member
                      • Mar 2009
                      • 21

                      #11
                      Hi acoder, the variable im picking is a result of my query that is displayed in a list and I have a select button (below) to catch the value of the row (which is the contactid)
                      but still not working (sigh*) I hope im almost there.

                      Code:
                      echo "<input type='button' value='Select' onclick='window.opener.document.getElementById( 'Contact' ).value = '". $row['contactid']."' ";

                      Comment

                      • Frinavale
                        Recognized Expert Expert
                        • Oct 2006
                        • 9749

                        #12
                        Sorry to bud in here but I remember something about having to set the name of the parent window for the opener to work....experts if I'm wrong here please correct me :)

                        Did you set the name of the Parent window before opening the Child window (popup window)?

                        For example:
                        Code:
                        <body onload="window.name='ParentWindowName'">

                        Aside from that, I would recommend that you put your JavaScript in a method instead of directly in the button click event. This is simply easier to read especially if you have "if" statements....f or example....Oh! wait a sec...By rewriting your JavaScript into a function I found your problem.

                        You're attempting to access a variable that exists on the server in your JavaScript code. You cannot access $row['contactid'] in your JavaScript method because this variable exists on the server.

                        Well, actually this might not be your problem if your list submits the page to the PHP code when the users selects something...the n your button would have had the correct values. Regardless, I believe that you have looked over this fact. (Maybe, I should just stick with .NET :) )

                        Try retrieving the selected value using JavaScript in order to set the text box in your parent page.


                        For example (the following assumes that you're attempting to print an item selected in a <select> list with the ID = "idOfList") :
                        Code:
                        echo "<script type='text/javascript'>"
                        echo " function setTextBoxValue(){"
                        echo "   if (window.opener && !window.opener.closed) {"
                        echo "     var dropDownList = document.getElementById('idOfList');"
                        echo "     var selectedIndex = dropDownList.selectedIndex;"
                        echo "     var selectedValue = dropDownList[dropdownIndex].value;"
                        echo "     window.opener.document.getElementById('Contact').value = selectedValue ;" 
                        echo "   }"
                        echo "}"
                        echo "</script>
                        echo "<input type='button' value='Select' onclick='setTextBoxValue();' />"



                        -Frinny

                        Comment

                        • mychikka
                          New Member
                          • Mar 2009
                          • 21

                          #13
                          a little progress here... my java is functioning except it didn't catch the value

                          My Java on to of the <body> tag

                          Code:
                          <script language="javascript"> 
                          function contactid(contactid) 
                          { 
                          window.opener.document.getElementById( 'Contactid' ).value =textcontactid; 
                          window.close(); 
                          } 
                          </script>
                          MY PHP CODE -- I put the value to pick on the text box
                          Code:
                          echo "<td><input type='text' name=\"textcontactid\" value='". $row['contactid']. "'>";
                          echo "<input type='button' value='". $row['contactid']. "' onclick=\"contactid()\" >";

                          RESULT:

                          [object] --- SHOWS ON MY PARENT WINDOW TEXT BOX

                          please help :(

                          Comment

                          • mychikka
                            New Member
                            • Mar 2009
                            • 21

                            #14
                            and my parent input box looks like this....

                            Code:
                            echo "<td width='100%'>
                            	<input type=\"text\" name=\"contactid\" onclick=\"window.open('contact_search_sub.php')\"></input>";

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              A few things:
                              1.. Watch out for the case. "contactid" and "Contactid" are NOT the same.
                              2. The number of parameters has to be correct.
                              3. In your function, you have textcontactid, but you've not set it anywhere. I would suggest passing the value in the function, e.g. when calling the function, you could use "contactid(this .form.textconta ctid.value)"

                              Comment

                              Working...