SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript include

    hi to everybody, I have a problem on an input field of a form which I have associated an Onchange event to.
    The Onchange event recalls the following Javascript function:

    <Script language="javascript">
    function Cambia()

    {


    document.write('<' + 'script language="javascript" type="text/javascript" src="listalocalita5.js" ><\/script>');



    }
    </Script>




    The code does not execute and the window of the Browser closes.
    If instead I explode the code of the Script inside the function executes it correctly.
    Can someone tell me because?
    I thank in advance whoever will want to answer me.

    Fullavia

  2. #2
    SitePoint Zealot sajjad's Avatar
    Join Date
    May 2005
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don not use document.write just include the file

  3. #3
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    The reason is quite simple:
    Any external Javascript documents must be loaded while the page is loading. When you use a function-based document.write to include the Javascript file, it's never loaded - the only thing that happens is that the code is written to the page.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!


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
  •