Does javascript have problems with two similar script in the same page?

Discussion in 'JavaScript' started by Jen-, Oct 30, 2006.

  1. #1
    Hi, seem to be having a problem with a similar script in the same .html page. Even though I changed the function names etc. One uses page load, the other uses window.load. Only one of them will work. Does javascript have a problem with both in the same page? If so, why please. Thank you very much!
     
    Jen-, Oct 30, 2006 IP
  2. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    No javascript have not problems with two similar script in the same page, but,
    If those scripts use same variables names, functions names and more names :), then we have a problem,

    B.T.W

    You can allow 2 functions to run with page load like this :
    <body onload="function();function_two();">
    HTML:
     
    Morishani, Oct 30, 2006 IP
  3. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    OK, hi Morishani, thanks for the good tip. I have them named with different functions but they have alike variables. Because they are the same exact scripts connected twice externally they need to use one onload function. But read my next message below, there is still a big problem left.
     
    Jen-, Oct 31, 2006 IP
  4. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    OK heres another code to include more than one body onload function.
    <script type="text/javascript">window.onload=function(){outImage('owned');inImage('put');}</script>

    So both alike scripts work on the same page. But now I have to time them exactly the same. Otherwise one script is picking up the timing of the other. Even with separate function names. Anyone know how to get around this without using an I-frame? To inlcude both scripts on the same page? Thanks.
     
    Jen-, Oct 31, 2006 IP
  5. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You need to change the variable names or just combine the 2 scripts into 1 big script.
     
    mad4, Oct 31, 2006 IP