Results 1 to 4 of 4

Thread: Loading Javascript dynamically using Hyperlinks

  1. #1
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Loading Javascript dynamically using Hyperlinks

    Hello,

    I was wondering if someone might be able to help me with this please?

    Im trying to create a website which has a few similar pages, on each page the only thing that really changes is the title of the page and some dynamic content which is loaded using javascript files.

    I have a simple hyperlink menu system, which loads each page reloading essentially the same pages again with a few minor changes, I was wondering is it possible to load the javascript files dynamically depending on the hyperlink presses

    Eg
    <a href="javascript:change(1)">Page one</a>
    <a href="javascript:change(2)">Page Two</a>
    <div ID="myID"></div>

    <script type="text/javascript">

    function Change(myPage){
    if (myPage == "1"){
    myID.innerHTML="Welcome to Page One<scrip"+"t src=\"http://www.mysite.com/1.jsp"></scrip"+"t>";
    }
    else{
    myID.innerHTML="Welcome to Page Two<scrip"+"t src=\"http://www.mysite.com/2.jsp"></scrip"+"t>";
    }
    }
    </script>

    Im not too sure if this is making any sense, I really just want to have one html page but just change the center contents dynamically via hyperlinks???

    I have tried a few things but either the javascript doesnt load at all or it displays the contents on another page??? The text portion works where it changes the text dynamically its just a problem changing the javascript page to load...

    I really hope someone can help if this is even possible to do lol
    Last edited by c9679; 08-20-2005 at 11:18 AM.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You've missed escaping some quotes.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I know thank you but that was just a simple example not the full code that i have tried, but its similar to some of the bits that I have tried but non have worked, it either doesnt execute the script at all or it clears the page and displays the script... Would be really gratefull for any help

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by c9679
    Im trying to create a website which has a few similar pages, on each page the only thing that really changes is the title of the page and some dynamic content which is loaded using javascript files.
    Don't use client-side scripting at all. Either use separate files coupled with server-side includes or a server-side language to include the common sections, or use the latter to include the content amongst common code.

    If neither option is available (and they are the best), use an iframe and target your links to that frame.

    Mike

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
  •