Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 10th, 2004, 10:17 AM
Friend of Wrox
 
Join Date: Apr 2004
Location: Wausau, WI, USA.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default Advice on Dynamically assigning external js file

I have a web page that has the following code...

    switch (optwizsel)
    {
        case "YYP":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard1.js'></scr" + "ipt>");
        break;
        case "YNP":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard2.js'></scr" + "ipt>");
        break;
        case "NYP":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard3.js'></scr" + "ipt>");
        break;
        case "NNP":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard4.js'></scr" + "ipt>");
        break;
        case "YYY":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard5.js'></scr" + "ipt>");
        break;
        case "YNY":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard6.js'></scr" + "ipt>");
        break;
        case "NYY":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard7.js'></scr" + "ipt>");
        break;
        case "NNY":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard8.js'></scr" + "ipt>");
        break;
        case "YYN":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard5.js'></scr" + "ipt>");
        break;
        case "YNN":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard6.js'></scr" + "ipt>");
        break;
        case "NYN":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard7.js'></scr" + "ipt>");
        break;
        case "NNN":
            window.document.write("<scr" + "ipt language='JavaScript' src='setup/alerts/alertwizard8.js'></scr" + "ipt>");
        break;
        default:
        break;
    }

Basically all it does is go through a routine of checking a unix server for the config of certain items and based upon that config writes the appropriate statement in the head to assign the correct external js file.

Here is my question and the advice I am needing...This has the high probability of expanding in the future beyond checking the three config options I am checking today. My concern is complexity and size of the page. Ideally what I would love to do is assign an external js file that simply does the checking and writes the appropriate code line to assign the correct js file to the page. Is this possible? Is it possible to have an external js file that writes to the head an external js file?

And if anyone has any other ideas, I am open to them.

Clay Hess
__________________
Clay Hess
Reply With Quote
  #2 (permalink)  
Old June 10th, 2004, 10:56 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I don't think you can do this, but I would suggest a server language like PHP, ASP or CGI if it works with you.

HTH,

Snib

<><
Reply With Quote
  #3 (permalink)  
Old June 10th, 2004, 11:40 AM
Friend of Wrox
 
Join Date: Apr 2004
Location: Wausau, WI, USA.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib,

Thanks for the advice. Unfortunately, while I would love to use ASP or something of that nature, in this case we cannot. The unix server I am communicating with is not a web server. It is simply a server our company sells with our own custom programs on them and I interact with it. So a server side language is out of the question right now.

Clay Hess
Reply With Quote
  #4 (permalink)  
Old June 10th, 2004, 11:48 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I have another idea: can you make the page a .shtml and then use an #include statement to include your JavaScript from a separate file?

Snib

<><
Reply With Quote
  #5 (permalink)  
Old June 10th, 2004, 01:07 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Wausau, WI, USA.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib,

Usually when I am including files and such from a server side, I am using ASP. So I am not as familiar with shtml and the ramifications so let me ask you some things...

This webpage is being hosted locally on the users harddrive. Can shtml and the include code reference a local file and not be server side at all? Basically, the only interaction I have with the unix server is getting config info in a boolean format. SO do you think that would work?

Clay Hess
Reply With Quote
  #6 (permalink)  
Old June 10th, 2004, 01:57 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hmm... I can't get it to work locally, but it would with IIS or Apache installed locally. I know you don't have either on the Unix box, and I'm guessing you don't have them locally, either.

Hope you solve this!

Snib

<><
Reply With Quote
  #7 (permalink)  
Old June 10th, 2004, 03:00 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Wausau, WI, USA.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have IIS on my machine but I of course cannot control what is on the users machine. So that would not work. Let me know if inspiration strikes you again.

Clay Hess
Reply With Quote
  #8 (permalink)  
Old June 10th, 2004, 03:36 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

How about shuffling your files a bit around, renaming them, and then use this code:

window.document.write("<scr" + "ipt type='text/javascript' src='setup/alerts/alertwizard' + optwizsel + '.js'></scr" + "ipt>");

Endless possibilities. Just change the value of optwizsel and add more .js files.....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #9 (permalink)  
Old June 10th, 2004, 03:42 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Yeah, that's a good idea. Something like this:

function IS(num) //IS = include script
{
 document.write("<scr" + "ipt type='text/javascript' src='setup/alerts/alertwizard' + num + '.js'></scr" + "ipt>");
}

switch(optwizsel)
{
 case "NNN" : IS(8); break;
}

That would greatly reduce the size of your page.

Snib

<><
Reply With Quote
  #10 (permalink)  
Old June 10th, 2004, 05:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

There is some examples of different methods at http://www.codehouse.com/javascript/articles/external/ which cover this and may be of assistance.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
External JS files Ben Horne Javascript 3 July 25th, 2008 02:00 AM
dynamically link js file darkhalf Javascript 3 September 15th, 2006 09:05 AM
Thoughts on Dynamically assigning external js file fs22 Javascript 1 June 23rd, 2004 02:12 PM
refreshing external js file fs22 Javascript How-To 1 June 17th, 2004 05:02 PM
Dynamically assign external js file fs22 Javascript How-To 1 May 21st, 2004 05:22 PM



All times are GMT -4. The time now is 05:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.