SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard Pedro Monteiro's Avatar
    Join Date
    Sep 2002
    Location
    Lisbon
    Posts
    1,393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Onloading two functions at the same time

    First of all I appologize beforehand for my complete ignorance of javascript.

    What I am trying to do here is to load two functions at the same time. These functions are triggered by two images that scroll down a css positioned box.

    Now the problem that I am facing is that I can only get one function to work properly. The one who is loaded in last place. Why is this happening?

    Best regards.

    PHP Code:
    <SCRIPT language=JavaScript><!--
    window.onload = function () {
     
    ijsw ScrollWindow(396427"IJPageContent""IJPageContentContainer""IJPageScrollUp""IJPageScrollDown");
    }
    //--></SCRIPT>
    <SCRIPT language=JavaScript><!--
    window.onload = function () {
     
    ijswb ScrollWindow(396427"IJPageContentb""IJPageContentContainerb""IJPageScrollUpb""IJPageScrollDownb");
    }
    //--></SCRIPT> 
    PHP Code:
    <DIV id=IJPageScrollUpb><A onmouseup="StopScroll(); return false;" onmousedown="ScrollUp('ijswb',-8);return false;" onclick="return false;" onmouseout=StopScroll() href="#"><IMG height=16 src="../images/ijup.gif" width=21 border=0></A></DIV>
          <
    DIV id=IJPageScrollDownb><A onmouseup="StopScroll(); return false;" onmousedown="ScrollDown('ijswb',8);return false;" onclick="return false;" 
    onmouseout=StopScroll() href="#"><IMG height=16 src="../images/ijdown.gif" width=21 border=0></A></DIV
    PHP Code:
           <DIV id=IJPageScrollUp><A onmouseup="StopScroll(); return false;" onmousedown="ScrollUp('ijsw',-8);return false;" onclick="return false;" onmouseout=StopScroll() href="#"><IMG height=16 src="../images/ijup.gif" width=21 border=0></A></DIV>
          <
    DIV id=IJPageScrollDown><A onmouseup="StopScroll(); return false;" onmousedown="ScrollDown('ijsw',8);return false;" onclick="return false;" onmouseout=StopScroll() href="#"><IMG height=16 src="../images/ijdown.gif" width=21 border=0></A></DIV

  2. #2
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't really have two functions here, you have one function literal being assigned to the window.onload event. It's just being assigned, with the same parameters, twice.

    You can have the same function operate on two objects, but you must pass the objects to the function as separate entities. Here, you have assigned an event to a function literal. That event is singular and can only be ascribed to one function as a consequence.

    You can approach this a couple different ways. If you want to stick with the function literal approach, you will have to change the function to act on the two different objects separately, but in unison.

  3. #3
    SitePoint Wizard Pedro Monteiro's Avatar
    Join Date
    Sep 2002
    Location
    Lisbon
    Posts
    1,393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you JVLB, I think I get the general concept of what you are saying. But how do I make the function act on the two objects seperatly?

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The parameters are different, and those are two functions: a function literal generates the same function object as the function keyword, or the Function() constructor. It's just a different syntax. And window.onload isn't an 'event', it's an event handler (handling a load event); HTML event handlers are object properties (variables) so, assigning a handler function to one on one line and doing it again on another simply overwrites the first, as with any variable. DOM addEventListener() and IE-specific attachEvent() allow for non-destructive (multiple) handler assignments; you can also use code that 'bundles' previous assignments with new ones, or simply hardcode in the multiple assignments as one.

    That looks like Dan Steinman's ScrollWindow constructor you've got there...it looks like you're trying to generate two instances of that object in your...frameset? Hard to tell. If so:
    Code:
    onload = function ()
    {
       ijsw = new ScrollWindow(396, 427, "IJPageContent", "IJPageContentContainer", "IJPageScrollUp", "IJPageScrollDown");
       ijswb = new ScrollWindow(396, 427, "IJPageContentb", "IJPageContentContainerb", "IJPageScrollUpb", "IJPageScrollDownb");
    }
    ...should do the trick. btw: functions are called, documents (and occasionally adios) are loaded.
    ::: certified wild guess :::

  5. #5
    SitePoint Wizard Pedro Monteiro's Avatar
    Join Date
    Sep 2002
    Location
    Lisbon
    Posts
    1,393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Adios, thank you my friend. I'm going to try and implement that

  6. #6
    SitePoint Wizard Pedro Monteiro's Avatar
    Join Date
    Sep 2002
    Location
    Lisbon
    Posts
    1,393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Adios, that worked perfectly. Thank you so much.

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pedro, amigo...just noticed you weren't calling that constructor - if it is a constructor - with the new keyword, required with constructor functions to generate a new object instance. Added it above, as I can't imagine what else it could be. Post more details if you like.

    adios

    Edit:

    Never mind! (don't mess w/success)
    ::: certified wild guess :::

  8. #8
    SitePoint Wizard Pedro Monteiro's Avatar
    Join Date
    Sep 2002
    Location
    Lisbon
    Posts
    1,393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Muito obrigada adios!!

    You saved me hours of trying to figure out something of which I know nothing about.

    Thank you very much!

  9. #9
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by adios
    The parameters are different, and those are two functions:
    My mistake. I had my contacts in the wash last night and missed the 'b's. Apologies all 'round.
    Last edited by JVLB; Jun 27, 2004 at 12:56.


Bookmarks

Posting Permissions

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