call form1 javascript function from form2 function?

Last post 07-06-2009 6:01 AM by tnystedt. 4 replies.

Sort Posts:

  • call form1 javascript function from form2 function?

    07-06-2009, 2:56 AM
    • Member
      42 point Member
    • tnystedt
    • Member since 06-16-2009, 3:03 AM
    • Posts 93

    Hi,

    Is it possible to call a funtion that is located in "form1" from a javascript function in another form("form2")? Maybe something like this?


    Default.aspx:


    <html xmlns="http://www.w3.org/1999/xhtml">
    <script language= javascript type="text/javascript">

        function Test() {
            //something something..
        }
        
    </script>

    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        </div>
        </form>
    </body>
    </html>



    Default2:


    <html xmlns="http://www.w3.org/1999/xhtml">

    <script language= javascript type="text/javascript">

        function Test2() {
            form1.Test();
        }
        
    </script>

    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form2" runat="server">
        <div>
        
           
        </div>
        </form>
    </body>
    </html>


  • Re: call form1 javascript function from form2 function?

    07-06-2009, 5:15 AM
    • Member
      242 point Member
    • Slicksim
    • Member since 01-29-2007, 8:25 PM
    • Lancaster, UK
    • Posts 45

    Hi,

    afraid not, the page will no longer exist when you navigate away from it.

    if you want to access common functions in javascript, then you should place them in a seperate file and link them into both pages and use from them there.

    Regards

    Simon C

  • Re: call form1 javascript function from form2 function?

    07-06-2009, 5:38 AM
    • Member
      42 point Member
    • tnystedt
    • Member since 06-16-2009, 3:03 AM
    • Posts 93

    Actually I don't think I navigate away from it, the "form2" is a popup window. On the popup page I have some checkboxes and a linkbutton...and when I press the linkbutton I want it to close the popup and send some variables to a "form1-function", isn't this possible? if not, do somebody have any suggestions how this could be solved? (its not common function)

  • Re: call form1 javascript function from form2 function?

    07-06-2009, 5:46 AM
    Answer
    • Contributor
      2,387 point Contributor
    • maverickhyd
    • Member since 03-25-2009, 6:38 AM
    • Posts 416

     Hi,

    use window.opener.functioninform1();

     Check this Article

    http://www.devx.com/tips/Tip/38701

     

    Please Mark as Answer if it helped You!
  • Re: call form1 javascript function from form2 function?

    07-06-2009, 6:01 AM
    • Member
      42 point Member
    • tnystedt
    • Member since 06-16-2009, 3:03 AM
    • Posts 93

    Hi maverick,

    Thank you so much :D, it worked!! Thank you!!! :)

    /Tobias


    maverickhyd:

     Hi,

    use window.opener.functioninform1();

     Check this Article

    http://www.devx.com/tips/Tip/38701



Page 1 of 1 (5 items)