pass values from popup window to another popup window

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vjayis
    New Member
    • Mar 2008
    • 134

    pass values from popup window to another popup window

    hi

    i am having a form which contains an text field.,

    when the submit button is clicked the value of the textfield should be taken into the new popup window to display the results.

    i had tried but didnt get the solution.,

    could anyone help me

    here is my code;

    (page name=first.php)


    Code:
    <script type="text/javascript">
    function Newpopup(text)
    {
      var  dd=document.getElementById("qq").value;
      window.opener.document.newpopup_formname.fieldname.value = dd; 
      win=window.open(text,'','width=1010px,height=800px,scrollbars=yes');
    }
    </script>
    
    
    <?
    $act=$_REQUEST['act'];
    $qq=$_POST['qq'];
    
    if($act==1)
    {
    ?>
    <meta http-equiv="refresh" content="0;javascript:Newpopup('new_pop.php')" >
    <?
    }
    ?>
    
    
    <form name="form1" id="form1" action="first.php?act=1" method="post">
    
    text field:<input type="text" id="qq" size="18" name="qq" value="<? if($act==1) echo $qq;?>">
    
    <input name="submit" type="submit" value="Submit" />
    
    </form>

    so when i enter the value and click the submit button., the page gets reloaded but no pop-up window is popped out.,


    thanks
    regards
    vijay
  • vjayis
    New Member
    • Mar 2008
    • 134

    #2
    hi

    got the solution

    worked it out and finally got it.,

    thanks

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      So how did you solve it? Post your solution for the benefit of anyone passing by.

      Comment

      • vjayis
        New Member
        • Mar 2008
        • 134

        #4
        Originally posted by acoder
        So how did you solve it? Post your solution for the benefit of anyone passing by.

        yes with pleasure.,and sorry for the delay

        here is the solution


        consider this page as the popup window page and the page name as first.php.,

        Code:
        <script type="text/javascript">
        function Newpopup(text)
        {
              win=window.open(text,'','width=1010px,height=800px,scrollbars=yes');
        }
        </script>
         
        <?
              $act=$_REQUEST['act'];
              $qq=$_POST['qq'];
              if($act==1)
               {
                    $newpopup="new_pop.php?data1=".$qq;
        ?>
               <meta http-equiv="refresh" content="0;javascript:Newpopup('$newpopup')" >
        <?
               }
        ?>
         
             <form name="form1" id="form1" action="first.php?act=1" method="post">
              text field:<input type="text" id="qq" size="18" name="qq" >
              <input name="submit" type="submit" value="Submit" />
              </form>

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Hmm, interesting use of the meta refresh tag. What I'd do is avoid that by using JavaScript directly to open the window during page load and pass the value in the URL, e.g.
          Code:
          <script type="text/javascript">
          function Newpopup(text)
          {
                win=window.open(text,'','width=1010px,height=800px,scrollbars=yes');
          }
          <?
                $act=$_REQUEST['act'];
                $qq=$_POST['qq'];
                if($act==1)
                 {
                      $newpopup="new_pop.php?data1=".$qq;
          ?>
          echo "Newpopup('$newpopup')";
          <?
                 }
          ?>
          </script>
          
               <form name="form1" id="form1" action="first.php?act=1" method="post">
                text field:<input type="text" id="qq" size="18" name="qq" >
                <input name="submit" type="submit" value="Submit" />
                </form>
          Oh, and thanks for posting.

          Comment

          • vjayis
            New Member
            • Mar 2008
            • 134

            #6
            hi

            i am with an problem once again.,

            it works well in firefox., but in IE it does'nt.

            the poup window gets refreshed again and again whereas the new popup was not popped out.,


            tried even by replacing the meta http to the javascript given by u., but it does'nt get worked .,The function itself was not called., coz its taking the variable as the string and just printing the full statement.,

            checked the semicolon in the meta http(already got problem with this)., but it seems to be perfect.,

            regards
            vijay

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              That was a mistake on my part. Remove the closing and opening PHP tags:[code=php]<?
              $act=$_REQUEST['act'];
              $qq=$_POST['qq'];
              if($act==1)
              {
              $newpopup="new_ pop.php?data1=" .$qq;
              echo "Newpopup('$new popup');";
              }
              ?>[/code]

              Comment

              • vjayis
                New Member
                • Mar 2008
                • 134

                #8
                cool., i didnt made mistake on this,.

                i had written the code lik this only., but didnt got solution.,

                i tried by using the below code.,
                Code:
                <?
                           $act=$_REQUEST['act'];
                            $qq=$_POST['qq'];
                            if($act==1)
                             {
                                  $newpopup="new_pop.php?data1=".$qq;
                                  echo "Newpopup('$newpopup');";
                             }
                ?>
                <script type="text/javascript">
                function NewWindowd(links)
                {
                  win=window.open(links,'','width=1010px,height=800px,scrollbars=yes');
                }
                
                </script>
                got the resultas -> Newpopup('new_p op.php?data1=da ta'); <-

                simply the line gets displayed., function is not called.

                and even tried by replacing the function even without sending any values.,
                but didnt yet called the function.,

                Code:
                	echo '<script type="text/javascript">NewWindowd();</script>';

                but i need to send values to the new popup.,

                the meta http works well in firefox., but not in IE.,


                help me to get rid of this.,

                thanks

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by vjayis
                  got the resultas -> Newpopup('new_p op.php?data1=da ta'); <-

                  simply the line gets displayed., function is not called.
                  That's because it's not within script tags. Move the echo to within HTML <script> tags.

                  Whatever you try, check the source in the browser (View -> Source) and post that here.

                  Comment

                  • vjayis
                    New Member
                    • Mar 2008
                    • 134

                    #10
                    Originally posted by acoder
                    That's because it's not within script tags. Move the echo to within HTML <script> tags.

                    Whatever you try, check the source in the browser (View -> Source) and post that here.

                    hi

                    tried by the changes given by u.,
                    still didnt get the solution.

                    tried just to call the function without passing any values., but that too was not called.,

                    Code:
                     <?
                              $act=$_REQUEST['act'];
                               $qq=$_POST['qq'];
                                if($act==1)
                                {
                    ?>
                    
                    <script type="text/javascript">
                    <? echo "Newpopup()";?>
                    </script>
                    
                    <?
                                }
                    ?>
                    <script type="text/javascript">
                          function NewWindowd()
                          {
                           alert("function called");
                            win=window.open(links,'','width=1010px,height=800p  x,scrollbars=yes');
                          }
                    </script>
                    this was in the view source before submitting the form.,
                    Code:
                    <script type="text/javascript">
                    function NewWindowd()
                    {
                    
                      alert("function called");
                      win=window.open(text,'','width=1010px,height=800px,scrollbars=yes');
                    }
                    
                    </script>
                    and after submitting this was in the view source.,

                    Code:
                    <script type="text/javascript">
                     NewWindowd()</script>
                    
                    <script type="text/javascript">
                    function  NewWindowd()
                    {
                    
                      alert("function called");
                      win=window.open(text,'','width=1010px,height=800px,scrollbars=yes');
                    }
                    
                    </script>
                    note:the function was not called even in firefox.


                    And even tried just by simply writing the code as below
                    Code:
                    $act=$_REQUEST['act'];
                    $qq=$_POST['qq'];
                    //echo $act;
                    if($act==1)
                    {
                    ?>
                    <script type="text/javascript">
                    NewWindowd();
                    </script>
                    
                    <?
                    }
                    ?>
                    <script type="text/javascript">
                    function NewWindowd()
                    {
                    
                      alert("function called");
                      win=window.open(text,'','width=1010px,height=800px,scrollbars=yes');
                    }
                    
                    </script>
                    but that too didnt get worked.,


                    i very much in need of this script to work., help me in this

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      You've not set "text" (the first parameter to window.open()). Either pass it as a parameter to the NewWindowd() function or set a variable text globally.

                      Comment

                      • vjayis
                        New Member
                        • Mar 2008
                        • 134

                        #12
                        Originally posted by acoder
                        You've not set "text" (the first parameter to window.open()). Either pass it as a parameter to the NewWindowd() function or set a variable text globally.

                        Tried doing the changes., but no changes found.,

                        the function itself is not called if i m calling it through php echo statement.,

                        Not even an alert message is displayed.,

                        Code:
                        <?
                              $act=$_REQUEST['act'];
                              $qq=$_POST['qq'];
                              if($act==1)
                              {
                              echo '<script type="text/javascript">NewWindowd();</script>';
                              }
                              ?>
                              <script type="text/javascript">
                              function NewWindowd()
                              {
                                alert("function called");
                                var dd=document.getElementById("qq").value;
                                var text="new_pop.php?data1="+dd;
                                win=window.open(text,'','width=1010px,height=800px  ,scrollbars=yes');
                              }
                             </script>
                        In the form ., the value is stored in an hidden field named and having id as "qq";
                        and that value is taken back in the javascript.,
                        and even tried by using
                        Code:
                        var dd=document.form1.qq.value;
                        but nothing happens.,


                        The function itself didnt get called then how can these things happpen??
                        Even an alert message was displayed.,

                        Anyother way to solve this.,

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          If the hidden field is not set after submit, or you're calling JavaScript code during page load, it won't be available to JavaScript. Try the code I gave earlier:
                          Code:
                          <html>
                          <head>
                          <script type="text/javascript">
                          function Newpopup(text) {
                              win=window.open(text,'','width=1010px,height=800px,scrollbars=yes');
                          }
                          <?
                              $act=$_REQUEST['act'];
                              $qq=$_POST['qq'];
                              if ($act==1) {
                                  $newpopup="new_pop.php?data1=".$qq;
                                  echo "Newpopup('$newpopup');";
                              }
                          ?>
                          </script>
                          </head>
                          <body>
                              <form name="form1" id="form1" action="first.php?act=1" method="post">
                              text field:<input type="text" id="qq" size="18" name="qq" >
                              <input name="submit" type="submit" value="Submit" />
                              </form>
                          </body>
                          </html>
                          If it doesn't work, maybe you have a popup blocker running.

                          Comment

                          • vjayis
                            New Member
                            • Mar 2008
                            • 134

                            #14
                            Hi

                            got the solution.,

                            the popup doesnt popped out because i hav written the script below the form the page gets loaded., so it was not included in the fresh page.,

                            when i placed the script before the form it gets working.,

                            thanks for ur help

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              Hmm... I thought you already had it before the form - see first few posts.

                              Anyway, glad it's working.

                              Comment

                              Working...