By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,280 Members | 2,193 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,280 IT Pros & Developers. It's quick & easy.

dynamic equivalent ?

P: n/a
this works as shown:

<script Language="javascript" src="http://127.0.0.1/syndicate.ashx?d=suppliers"></script>

is there a way to set src programmatically ??
Sep 25 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a

Jon Paal wrote:
this works as shown:

<script Language="javascript" src="http://127.0.0.1/syndicate.ashx?d=suppliers"></script>

is there a way to set src programmatically ??
It uses my own library as an example, but this did work for me:

<html>

<body>
<script id="script1" type="text/javascript"></script>

<script type="text/javascript">
document.getElementById("script1").src="/Ajax/ajax.js";
</script>

<script type="text/javascript">
var ajax = new AjaxRequest();

ajax.doTextRequest("http://www.google.com", "GET", "", update, true);

function update() {
document.getElementById("goog").innerHTML = ajax.getValue();
}
</script>

<div id="goog"></div>
</body>

</html>

Sep 25 '06 #2

P: n/a

i was hoping to get to something like below, but it doesn't return anything when src is dynamic. Only seems to work when src is in
the script tag at the time page is loaded.

====================================

<script Language="javascript" >

function switchsrc(id){
var mysrc;
switch (id)
{
case 1:
//alert (1);
mysrc = "suppliers";
break;
case 2:
//alert (2);
mysrc = "customers";
break;
}

document.getElementById("ashx").src = "http://127.0.0.1/syndicate.ashx?d=" + mysrc ;
}

</script><br>

<script type="text/javascript" id="ashx" ></script>

================================================

"Tom Cole" <tc****@gmail.comwrote in message news:11**********************@m7g2000cwm.googlegro ups.com...
>
Jon Paal wrote:
>this works as shown:

<script Language="javascript" src="http://127.0.0.1/syndicate.ashx?d=suppliers"></script>

is there a way to set src programmatically ??

It uses my own library as an example, but this did work for me:

<html>

<body>
<script id="script1" type="text/javascript"></script>

<script type="text/javascript">
document.getElementById("script1").src="/Ajax/ajax.js";
</script>

<script type="text/javascript">
var ajax = new AjaxRequest();

ajax.doTextRequest("http://www.google.com", "GET", "", update, true);

function update() {
document.getElementById("goog").innerHTML = ajax.getValue();
}
</script>

<div id="goog"></div>
</body>

</html>

Sep 25 '06 #3

P: n/a
Tom Cole said the following on 9/25/2006 4:11 PM:
Jon Paal wrote:
>this works as shown:

<script Language="javascript" src="http://127.0.0.1/syndicate.ashx?d=suppliers"></script>

is there a way to set src programmatically ??

It uses my own library as an example, but this did work for me:
Did you test it in anything besides IE? You should test it there as the
only UA that allows the changing of the .src property of a script
element is IE.

Although dynamically creating script elements is very widely supported,
you simply createElement('script') and then set it's .text property to
the script block.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 25 '06 #4

P: n/a
actually I'm testing in an hta file, which is IE
Did you test it in anything besides IE? You should test it there as the only UA that allows the changing of the .src property of a
script element is IE.

Although dynamically creating script elements is very widely supported, you simply createElement('script') and then set it's .text
property to the script block.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Sep 25 '06 #5

P: n/a
should show two tables but only one appears at a time and dynamic table never stops loading....

================================================== =========

<!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" >

<head >
<title></title>

<script type="text/javascript" >
function switchsrc(){
document.getElementById("ashx").src = "http://www.aspcode.net/articlesamples/synd/syndicate.ashx"
}
</script>
<style>
table
{
border-top: 1px solid #000000;
border-left: 1px solid #000000;
border-right: 1px solid #000000;
border-bottom: 1px solid #000000;
background-color: White;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #000000;
}
</style>
</head>
<body >
<input type="button" value="result-2" onClick="switchsrc()">
<br>
<script src="http://www.aspcode.net/articlesamples/synd/syndicate.ashx"></script>
<br>
<script id="ashx" ></script>
</body>
</html>
Sep 25 '06 #6

P: n/a
Jon Paal said the following on 9/25/2006 5:05 PM:
actually I'm testing in an hta file, which is IE
The claim was "this works" when it doesn't "work" reliably. It is always
nice though to see people back track to the "IE only" path only after
being told the hack code they were given is IE only. The other nice one
is "Its an IE only intranet".

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 25 '06 #7

P: n/a
the static version does work. in IE and firefox.
the question was how to make it dynamic.

Not sure what is meant by the rest of your message...
"Randy Webb" <Hi************@aol.comwrote in message news:Ut******************************@comcast.com. ..
Jon Paal said the following on 9/25/2006 5:05 PM:
>actually I'm testing in an hta file, which is IE

The claim was "this works" when it doesn't "work" reliably. It is always nice though to see people back track to the "IE only"
path only after being told the hack code they were given is IE only. The other nice one is "Its an IE only intranet".

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Sep 25 '06 #8

P: n/a
Jon Paal said the following on 9/25/2006 8:06 PM:

Your newsreader hasn't even made it to the level of being defective.
the static version does work. in IE and firefox.
Yep, that's the way external src= works.
the question was how to make it dynamic.
Search the archives for my name along with the function name of
loadJSFile and you will find this function:

function loadJSFile(fileURL){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.src = fileURL;
document.getElementsByTagName('head')[0].appendChild(newScript);
}

And call it as such:

loadJSFile('http://www.someDomain.com/someJSFile.js')

It is *that* simple.

Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 26 '06 #9

P: n/a
thanks for replying..

seems this just isn't going to work.

In Firefox the output replaces the entire page instead of filling a placeholder and page never finishes running.

Just won't work in IE, at all.

function loadJSFile(fileURL){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.src = fileURL;
document.getElementsByTagName('head')[0].appendChild(newScript);
}

And call it as such:

loadJSFile('http://www.someDomain.com/someJSFile.js')

It is *that* simple.

Sep 26 '06 #10

P: n/a
Jon Paal said the following on 9/25/2006 11:07 PM:
thanks for replying..

seems this just isn't going to work.
It will work, you just have to make it work.
In Firefox the output replaces the entire page instead of filling a placeholder and page never finishes running.
Then you probably have document.write statements in your .js files.
Just won't work in IE, at all.
Post a URL to a sample page.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 26 '06 #11

P: n/a

Randy Webb wrote:
Tom Cole said the following on 9/25/2006 4:11 PM:
Jon Paal wrote:
this works as shown:

<script Language="javascript" src="http://127.0.0.1/syndicate.ashx?d=suppliers"></script>

is there a way to set src programmatically ??
It uses my own library as an example, but this did work for me:

Did you test it in anything besides IE? You should test it there as the
only UA that allows the changing of the .src property of a script
element is IE.
No I didn't (obviously). I need to remember to do that when making
quick test cases for people like this....
>
Although dynamically creating script elements is very widely supported,
you simply createElement('script') and then set it's .text property to
the script block.
Thanks for the heads up. What if you wanted to include a prepackaged
..js file rather than an actual block of script?
>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 26 '06 #12

P: n/a
sample code

=======================================

<!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" >

<head>
<title>Data syndication from ASPCode.net</title>

<script type="text/javascript" >
function switchsrc(){
var d =document.getElementById('divContents').getElement sByTagName("script")
var t = d.length
var js = document.createElement('script');
js.type = "text/javascript";
document.getElementById('divContents').appendChild (js);
js.src = "http://www.aspcode.net/articlesamples/synd/syndicate.ashx" ;
}

function loadJSFile(){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.src = "http://www.aspcode.net/articlesamples/synd/syndicate.ashx";
document.getElementsByTagName('body')[0].appendChild(newScript);
}

</script>
<style>
table
{
border-top: 1px solid #000000;
border-left: 1px solid #000000;
border-right: 1px solid #000000;
border-bottom: 1px solid #000000;
background-color: White;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #000000;
}
</style>
</head>
<body >
<input id=button class="button" type="button" value="test 1" name="button" onClick="switchsrc()">
<input id=dbutton class="button" type="button" value="test 2" name="dbutton" onClick="loadJSFile()">
<br>
<script src="http://www.aspcode.net/articlesamples/synd/syndicate.ashx"></script>
<br>

<script id="ashx" ></script>

<div id="divContents"></div>

</body>
</html>
Sep 26 '06 #13

P: n/a
Tom Cole said the following on 9/26/2006 8:12 AM:
Randy Webb wrote:
>Tom Cole said the following on 9/25/2006 4:11 PM:
>>Jon Paal wrote:
this works as shown:

<script Language="javascript" src="http://127.0.0.1/syndicate.ashx?d=suppliers"></script>

is there a way to set src programmatically ??
It uses my own library as an example, but this did work for me:
Did you test it in anything besides IE? You should test it there as the
only UA that allows the changing of the .src property of a script
element is IE.

No I didn't (obviously). I need to remember to do that when making
quick test cases for people like this....
>Although dynamically creating script elements is very widely supported,
you simply createElement('script') and then set it's .text property to
the script block.

Thanks for the heads up. What if you wanted to include a prepackaged
..js file rather than an actual block of script?

Then you set the new script element's .src property instead of its .text
property:

function loadJSFile(fileURL){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.src = fileURL;
document.getElementsByTagName('head')[0].appendChild(newScript);
}

And call it as such:

loadJSFile('http://www.someDomain.com/someJSFile.js')

If you want to execute script code then use something like this:

function executeJSCode(stringToExecute){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.text = stringToExecute;
document.getElementsByTagName('head')[0].appendChild(newScript);
}

And call it as such:

executeJSCode('String of code here without script tags')

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 26 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.