PDA

View Full Version : Loading Javascript dynamically using Hyperlinks



c9679
08-20-2005, 11:14 AM
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

Twey
08-20-2005, 02:49 PM
You've missed escaping some quotes.

c9679
08-20-2005, 02:56 PM
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

mwinter
08-20-2005, 06:24 PM
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