PDA

View Full Version : Loading JS in the same id place..PLZ HELP



nospirit
01-05-2006, 08:48 AM
Dear all

I searched all the net about this Question but I could not find any script for it or any solution...
or if that can be or not ...

I need to click on button to load external js .
then to click on another button and load an external js in the same place of the first one

Please click to see the example :
http://www.creativelink-sy.com/example/test.html

Please inform me as soon as possible:confused:

Thanks in advance

jscheuer1
01-05-2006, 09:48 AM
First of all, you cannot use the document.write() method after a page is loaded without overwriting the entire page. Second, if all you want to do is change the background color of a table, there are much easier ways. With the type of layout your page has, a simple:


<input type="button" onclick="document.getElementsByTagName('table')[1].style.backgroundColor='blue'" value="Make Blue">

Would do the trick, if you give the red table an id, it would be even easier.

nospirit
01-05-2006, 10:22 AM
Thanks :
But I don't want to change colors...
I want to change the contain of the external js, the external js may contains tables - data - text - another design page ---elc...........
So the example what I need is to change the js with another one ..
Regards

jscheuer1
01-05-2006, 10:37 AM
Scripts can be swapped using AJAX and perhaps even using the method you have, changing the script tag's src attribute, I've never tested the latter method. However, the new script cannot contain just anything. As I just explained, the document.write() method is out, unless you do want the page overwritten. Also, anything in the new script that would normally execute as a page loads and/or on page load, will not execute simply because the script replaces one that did execute when the page was originally loaded. With these facts in mind, there is very little to be gained in swapping scripts. What exactly did you hope to accomplish?

nospirit
01-05-2006, 10:50 AM
Thanks buddy
Well , I exactly want to load exrenal js .the same as ifarme html pages.
but I don't want to use iframe...
So If there is any idea that I can load pages on click using extrenal js that's will helps me instead of using iframes.
Do u have any other idea?
Thanks

jscheuer1
01-05-2006, 11:30 AM
I'm still not clear on what, if anything concrete, you want to do. Try looking over the AJAX scripts offered here (http://www.dynamicdrive.com/dynamicindex17/indexb.html) to see if any are close. I also found one script specifically for loading javascripts:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script type="text/javascript">

var JSAdd;

function AddJS(name){
head=document.getElementsByTagName('HEAD')[0];
// next line removes the previously addid External JavaScript
if (JSAdd){ head.removeChild(JSAdd); }
JSAdd=document.createElement('SCRIPT');
JSAdd.type='text/javascript';
JSAdd.src=name;
head.appendChild(JSAdd);
}

function Test(){
alert('An External JavaScript\nhas not been Added');
}

</script>

</head>

<body>
<form name="add_query">
<input type="button" name="" value="Add JS fred.js" onclick="AddJS('fred.js');" /><br />
<input type="button" name="" value="Add JS tom.js" onclick="AddJS('tom.js');" /><br />
<input type="button" name="" value="Test" onclick="Test();" /><br />
</form>
</body>

</html>

Here are the two external files:

fred.js
_____________


function Test(){
alert('External JavaScript fred.js\nhas been Added');
}
_____________

tom.js
_____________


function Test(){
alert('External JavaScript tom.js\nhas been Added');
}
_____________

nospirit
01-05-2006, 11:37 AM
yeah thanks
I already have this script .. it invoke function only ...
anyhow... thanks alot buddy :)

nospirit
01-05-2006, 12:07 PM
WOW :::: Thanks a lot buddy WOW WOW WOW that's it .. really I have asked alot of programmers outthere surfing the net in many forums.. no one answered me ... I have found it in AJAX scripts yes you are the best you are really the best thanks a lot..................................10000000 1000 times

I love that....
Thanks