473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

dynamic equivalent ?

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
13 2127

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

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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Jason Tesser | last post by:
I work for at a college where I am one of 2 full-time developers and we are looking to program a new software package fro the campus. This is a huge project as it will include everything from...
6
by: bry | last post by:
Hi, I'm trying to do a dynamic import of a file that has no problems with it, that is to say I can import it normally, my sys.path is set to the right folder etc. but my dynamic import code is not...
14
by: Steven Taylor | last post by:
I'm learning C++ from C++ Primer Plus 5th edition. I'm struggling at the moment with declaring an array of three structures by using 'new' to allocate memory. (this is one of the programming...
5
by: swarsa | last post by:
Hi All, I realize this is not a Palm OS development forum, however, even though my question is about a Palm C program I'm writing, I believe the topics are relevant here. This is because I...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
3
by: sethwai | last post by:
Hi, I find the "snapshot for dynamic sql" a great tool for identifying the most frequently executed dynamic sql statements, most cpu used, etc. It is a great help for system tuning. My...
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
4
by: aarklon | last post by:
Hi all, recently a friend asked me is there any dynamic binding in C...?? to which i answered AFAIK it is in C++ only, but he says it is valid in C. if dynamic can be implemented via function...
3
by: saneman | last post by:
std::vector<intv creates a dynamic array where its possible to insert new elements without doing any preallocation. But how about a dynamic double array? I would like to have something like: ...
26
by: Aaron \Castironpi\ Brady | last post by:
Hello all, To me, this is a somewhat unintuitive behavior. I want to discuss the parts of it I don't understand. .... f= lambda: n .... 9 9
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.