SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onload does not work in div elements

    hi gurus,

    I have an onload handler that worked fine if applied in <body onload="getCountries()" >, but did not work in <div onload="getCountries()" >. I searched for a while in the forum and got no clue. How to solve this? I need to put it in <div> elements.

    Thanks a lot.
    Charlie

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Either stick that code in the body onload, or place it in a script tag just below the div, like
    <div></div>
    <script>getCountries();</script>

  3. #3
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi buddy
    there is no "onload" function for div tag
    so, if u want to execute the content of <div></div>
    first write <div></div> and its content and after that
    call the getCountries() function inside the <script></script> tag

    i hope this will help you
    if u have any query plz post

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi wysiwyg & Steve, thanks, that fixed my problem.

    I have this line:
    <script src="my7.js" language="JavaScript" type="text/javascript">
    in the html head, can I put it in a PHP function and echo this line and use the javscript as if it is in the html head?
    Thanks,
    Charlie

  5. #5
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Charlie

    what you are telling is fine, you can proceed


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
  •