Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call conditional javascript w/i javascript.

Status
Not open for further replies.

cote

IS-IT--Management
May 17, 2002
10
0
0
US
HELP!!!

I know how to call a javascript file using <script src:filename.js>. I really to call a javascript file depending on value of a variable. Please give me the code sample. Thanks a bunch.

In my HTML or Javascript code:

Let say the variable call count
The pseudo code: if (count == 1) {call help1.js}
if (count == 2) {call help2.js}
if (count == 3) {call help3.js}

Thanks a bunch.
 
You don't &quot;call&quot; JS files, you load them, then call the functions within them. Once a web page is completely loaded, you can't add any more external JS files to it, just call the functions that are already loaded. There's a way to conditionally load different JS files (though many - or maybe all - AOL browsers choke on this, from what I've encountered), but this doesn't look like what you want to do. Show some code from your page so we can get an idea of what you're trying to accomplish.
 
you could try if this is a server side variable :

<script src=&quot;script<%= integer %>&quot;></script>

if you are in a normal html page in the head :

<script>
var xyz = 'whatever';
document.write(&quot;<script src='script&quot; + xyz + &quot;.js'></script>&quot;)
</script>

Hope this helps.

PS : beer in europe is really good and I am drunk! :) Gary Haran
 
xutopia, beer in Canada is really good too :) and i'm on my way too. ;-)


dis
 
I don't understand why you need to call more than one js page, why not...
<script>
function 1()
{your function here}
function 2()
{your function here}
function 3()
{your function here}

function whereToGo()
{
var variable1 = &quot;WhatEverYouAreChecking&quot;
if(variable1 == 1)
{
function1()
}
else if (variable1 == 2)
{
function2()
}
else if (variable1 == 3)
{
function3()
}
else
{alert(&quot;You made an invalid selection&quot;)
}
}
</script>
<html>
<WhereEverYouWant onload=&quot;whereToGo()&quot;>
</html>


whether this in the actual html page or the js page shouldn't matter, then you have one js page that does everything which I think is basically what trollacious said.

in reality I have no idea what you are trying to do so take my post with a grain of salt.


dis
 
oui et &quot;la fin du monde&quot;!! we can buy those here too, but they call them imports (funny, eh?)


dis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top