pop up once

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • destiny007
    New Member
    • Feb 2008
    • 8

    pop up once

    Hi,

    can any one help me to create the pop up only once. on clicking the text box

    [HTML]<html>
    <head>
    <script type="text/javascript">
    function abc()
    {
    var wind1=null;
    var tmp=null;
    wind1 = window.open('', 'displayWindow' , 'width=400,heig ht=300,status=n o,toolbar=no,me nubar =no,scrollbars= no');
    wind1.document. write("<script> function alert1(f){");
    wind1.document. write("var frmdst=f.ta.val ue;");
    wind1.document. write("window.o pener.tmp=frmds t;");
    wind1.document. write("window.o pener.getValues ();");
    wind1.document. write("window.c lose();");
    wind1.document. write("}<\/script>");
    wind1.document. write("<html><b ody><form action='#' name='myform' method='post'>< TEXTAREA rows='2' cols='20' name='ta'></TEXTAREA><br><I NPUT type='button' value='save' onclick='javasc ript:alert1(thi s.form);'><INPU T type='button' value='cancel' onclick='javasc ript:window.clo se();'></form></body></html>");
    }
    function getValues()
    {
    document.forms["source"].elements["srctext"].value = tmp;
    }
    </script>
    </head>
    <body>
    <form action="#" name="source" method="get">
    <input type="text" onclick='abc(); ' name="srctext" value="" size="20" />
    </form>
    <body>
    </html>[/HTML]
    Last edited by gits; Feb 28 '08, 11:42 AM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    just use a variable:

    [CODE=javascript]var run = 0;
    [/CODE]
    when you click open the popup and set run to 1 ... in the open-window code check for run == 0 otherwise simply return from the opening function ...

    kind regards

    Comment

    • destiny007
      New Member
      • Feb 2008
      • 8

      #3
      Originally posted by gits
      just use a variable:

      [CODE=javascript]var run = 0;
      [/CODE]
      when you click open the popup and set run to 1 ... in the open-window code check for run == 0 otherwise simply return from the opening function ...

      kind regards
      Thanks alot..I tried it but after I am clicking cancel i am unable to get the popup again.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        since you didn't tell that that is a requirement this should be true :) ... just set the variable run in the opener back to 0 when you click cancel in your popup :)

        kind regards

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Try setting the value of run as 1 or 0 on click of the OK or Cancel (respectively) of the pop up window.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            Originally posted by hsriat
            Try setting the value of run as 1 or 0 on click of the OK or Cancel (respectively) of the pop up window.
            yup that would be a more straight way for the entire handling :)

            kind regards

            Comment

            • destiny007
              New Member
              • Feb 2008
              • 8

              #7
              Thanks!

              Can you please help me to write the code for resetting the value on Clicking "cancel" or "save".

              I think its not working as its a global variable.


              Regards.

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                in your popup use:

                [CODE=javascript]window.opener.r un = 1;
                [/CODE]
                onclick of save and set it to 0 when cancel is clicked.

                kind regards

                Comment

                • destiny007
                  New Member
                  • Feb 2008
                  • 8

                  #9
                  its still not working ...can you please rectify the errors.

                  here is the code

                  [HTML]<html>
                  <head>
                  <script type="text/javascript">
                  var run=0;
                  function abc()
                  {
                  if(run==0)
                  {
                  var wind1=null;
                  var tmp=null;
                  wind1 = window.open('', 'displayWindow' , 'width=400,heig ht=300,status=n o,toolbar=no,me nubar =no,scrollbars= no');
                  wind1.document. write("<script> function alert1(f){");
                  wind1.document. write("window.o pener.run = 1;");
                  wind1.document. write("var frmdst=f.ta.val ue;");
                  wind1.document. write("window.o pener.tmp=frmds t;");
                  wind1.document. write("window.o pener.getValues ();");
                  wind1.document. write("window.c lose();");
                  wind1.document. write("}<\/script>");
                  wind1.document. write("<html><b ody><form action='#' name='myform' method='post'>< TEXTAREA rows='2' cols='20' name='ta'></TEXTAREA><br><I NPUT type='button' value='save' onclick='javasc ript:alert1(thi s.form);window. opener.run = 0;'><INPUT type='button' value='cancel' onclick='javasc ript:window.clo se();window.ope ner.run = 0;'></form></body></html>");
                  }

                  }

                  function getValues()
                  {
                  document.forms["source"].elements["srctext"].value = tmp;
                  }

                  </script>
                  </head>
                  <body onload="">
                  <form action="#" name="source" method="get">
                  <input type="text" onclick='abc(); ' name="srctext" value="" size="20" />
                  </form>
                  <body>
                  </html>[/HTML]
                  Last edited by gits; Feb 29 '08, 04:32 PM. Reason: added code tags

                  Comment

                  • destiny007
                    New Member
                    • Feb 2008
                    • 8

                    #10
                    Thanks alot...!

                    its working now.:)

                    Comment

                    • gits
                      Recognized Expert Moderator Expert
                      • May 2007
                      • 5390

                      #11
                      hi ...

                      glad to hear that :) it seems that you had set the variable to 0 in both of the cases? ...

                      one note:

                      just use:

                      [CODE=javascript]onclick='window .opener.run = 0;'[/CODE]
                      the javascript: is useless today ...

                      kind regards

                      Comment

                      • destiny007
                        New Member
                        • Feb 2008
                        • 8

                        #12
                        Thanks a lot...! :)

                        Comment

                        • hsriat
                          Recognized Expert Top Contributor
                          • Jan 2008
                          • 1653

                          #13
                          Originally posted by gits
                          the javascript: is useless today ...
                          .... unless you have to call a JavaScript function in an href attribute.

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            Originally posted by hsriat
                            .... unless you have to call a JavaScript function in an href attribute.
                            ...which you shouldn't need to do unless it's a bookmarklet.

                            Comment

                            Working...