"onload" method

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JS

    "onload" method

    I have two functions in an external .js page:

    createMenu(sel) {
    document.write( "TEST1");
    }

    createFirstMenu (sel){
    document.write( "TEST2");
    }


    I have another page that includes this javaScript. In this page I use <body
    onload="createM enu('sel1');">:

    <body onload="createM enu('sel1')">
    <form name="sels" method="post" action="?page=j ubii">
    Kategori:&nbsp; &nbsp;&nbsp;
    <select name="sel1" id="sel1" onchange="creat eMenu('sel1','s el2');">
    </select>&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;
    <select name="sel2" id="sel2">
    <option value="" selected[color=blue]
    >-er- Vælg --</option>[/color]
    </select>
    &nbsp;
    <input name="search" type="text" id="search">
    &nbsp;
    <input type="submit" name="Submit" value="Søg">
    </form>

    "TEST1" get printed when I open this page as expected.

    But if I change onload to:
    <body onload="createF irstMenu('sel1' )">

    I don't get "TEST2" printed!


    What are the explanation?


  • JS

    #2
    Re: &quot;onload&qu ot; method


    "JS" <dsa.@asdf.co m> skrev i en meddelelse
    news:d7f59f$oo3 $1@news.net.uni-c.dk...[color=blue]
    > I have two functions in an external .js page:
    >
    > createMenu(sel) {
    > document.write( "TEST1");
    > }
    >
    > createFirstMenu (sel){
    > document.write( "TEST2");
    > }[/color]


    I tried to switch the order of the two methods:

    createFirstMenu (sel){
    document.write( "TEST2");
    }

    createMenu(sel) {
    document.write( "TEST1");
    }

    And now it works! But I don't know why....is it nessecary to write methods
    in a strict order?


    Comment

    • Daniel Kirsch

      #3
      Re: &quot;onload&qu ot; method

      JS wrote:[color=blue]
      > createFirstMenu (sel){
      > document.write( "TEST2");
      > }
      >
      > createMenu(sel) {
      > document.write( "TEST1");
      > }
      >
      > And now it works! But I don't know why....is it nessecary to write methods
      > in a strict order?[/color]

      No. Your give example works for me (if I add the word "function" before
      each function).

      You may give us an URL with an example so we may take a look.

      Daniel

      Comment

      Working...