Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with Window.Onload

    I have a function and the purpose of the function is to get two variables, pc1 and pc2. They are both getting their data from the same text box. pc1 should get the data when the page is onload, and pc2 should get it when the page is onbeforeunload. I have them in the same function so I can compare them, see if anything has changed, and then ask the user if they want to save. The problem I am having is distinguishing between which event the function has fired for:

    window.onload = func();
    windown.onbeforeunload = func();

    function func()
    {
    if (//some code needed here to see if its onload)
    var pc1 = textbox info
    if (//some code needed here to see if its onbeforeunload)
    var pc2 = textbox info

    if (pc1 ==pc2)
    (do something)
    }

    any help would be appreciated...

    }

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Code:
    window.onload = func();
    windown.onbeforeunload = func();
    func() means to execute right than and there.

    You need to attached it without the ()

    Code:
    window.onload = func;
    windown.onbeforeunload = func;
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by rihaszou View Post
    The problem I am having is distinguishing between which event the function has fired for:
    You could try:
    Code:
    window.onload = function(){func(true);}
    windown.onbeforeunload = function(){func(false)};
    
    function func(flag)
    {
     .............
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •