...

View Full Version : Nub Question. Referencing an external JS file?



Nosdo3
11-05-2010, 06:42 AM
Sorry, this is probably stupidly simple but I cannot seem to get this to work.

I would like to be able to reference the javascript externally.

I have tried the [code]<script type="text/javascript" src="dropdown.js"></script>[code]

I know I am missing something simple but I am still new at this.
Thanks

The code is:
[code]
<body>
<div id="SBO">
<FORM name="isc">
<table border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td nowrap height="11"> &nbsp;

<select name="example" size="1" onChange="redirect(this.options.selectedIndex)">
<option selected>Select Your Industry</option>
<option>Web Design</option>
<option>Photography</option>
<option>Media</option>
</select>
<br />

<select name="stage2" size="1" onChange="redirect1(this.options.selectedIndex)">
<option value=" " selected>Imprinted or Blank</option>
<option value=" " selected> </option>
<option value=" " selected> </option>
</select>
<br />

<select name="stage3" size="1" onChange="redirect2(this.options.selectedIndex)">
<option value=" " selected>Select your Budget </option>
<option value=" " selected> </option>
<option value=" " selected> </option>
</select>
<br />
<input type="button" name="test" value="Submit"
onClick="gothere()">
</td>
</tr>
</table>

</FORM>
</div>



<script>
<!--

/*
Triple Combo Script Credit
By Hamid Cheheltani/ JavaScript Kit (http://www.javascriptkit.com)
Visit http://javascriptkit.com for this and over 400+ other scripts
*/

var groups=document.isc.example.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option(" "," ");

group[1][0]=new Option("Customization"," ");
group[1][1]=new Option("Imprinted","47");
group[1][2]=new Option("Blank","46");

group[2][0]=new Option("Customization"," ");
group[2][1]=new Option("Imprinted","12");
group[2][2]=new Option("Blank","11");


group[3][0]=new Option("Customization"," ");
group[3][1]=new Option("Imprinted","87");
group[3][2]=new Option("Blank","86");

var temp=document.isc.stage2


function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
redirect1(0)
}



var secondGroups=document.isc.stage2.options.length
var secondGroup=new Array(groups)
for (i=0; i<groups; i++) {
secondGroup[i]=new Array(group[i].length)
for (j=0; j<group[i].length; j++) {
secondGroup[i][j]=new Array() }}

secondGroup[0][0][0]=new Option(" "," ");
secondGroup[1][0][0]=new Option("Select your Budget "," ");
secondGroup[1][1][0]=new Option(".25 to .99","http://W0Y.COM");
secondGroup[1][1][1]=new Option("$1.00 to $2.99","http://W1Y.com");
secondGroup[1][1][2]=new Option("$3.00 to $4.99","http://W3Y.com");
secondGroup[1][1][3]=new Option("$5.00 and up","http://W5Y.com");


secondGroup[1][2][0]=new Option("Select your Budget"," ");
secondGroup[1][2][1]=new Option(".25 to .99","http://W0N.COM");
secondGroup[1][2][2]=new Option("$1.00 to $2.99","http://W1N.com");
secondGroup[1][2][3]=new Option("$3.00 to $4.99","http://W3N.com");
secondGroup[1][2][3]=new Option("$5.00 and up","http://W5N.com");


secondGroup[2][0][0]=new Option("Select your Budget "," ");
secondGroup[2][1][0]=new Option(".25 to .99","http://P0Y.COM");
secondGroup[2][1][1]=new Option("$1.00 to $2.99","http://P1Y.com");
secondGroup[2][1][2]=new Option("$3.00 to $4.99","http://P3Y.com");
secondGroup[2][1][3]=new Option("$5.00 and up","http://P5Y.com");


secondGroup[2][2][0]=new Option("Select your Budget"," ");
secondGroup[2][2][1]=new Option(".25 to .99","http://P0N.COM");
secondGroup[2][2][2]=new Option("$1.00 to $2.99","http://P1N.com");
secondGroup[2][2][3]=new Option("$3.00 to $4.99","http://P3N.com");
secondGroup[2][2][3]=new Option("$5.00 and up","http://P5N.com");


secondGroup[3][0][0]=new Option("Select your Budget "," ");
secondGroup[3][1][0]=new Option(".25 to .99","http://M0Y.COM");
secondGroup[3][1][1]=new Option("$1.00 to $2.99","http://M1Y.com");
secondGroup[3][1][2]=new Option("$3.00 to $4.99","http://M3Y.com");
secondGroup[3][1][3]=new Option("$5.00 and up","http://M5Y.com");


secondGroup[3][2][0]=new Option("Select your Budget"," ");
secondGroup[3][2][1]=new Option(".25 to .99","http://M0N.COM");
secondGroup[3][2][2]=new Option("$1.00 to $2.99","http://M1N.com");
secondGroup[3][2][3]=new Option("$3.00 to $4.99","http://M3N.com");
secondGroup[3][2][3]=new Option("$5.00 and up","http://M5N.com");



var temp1=document.isc.stage3
function redirect1(y){
for (m=temp1.options.length-1;m>0;m--)
temp1.options[m]=null
for (i=0;i<secondGroup[document.isc.example.options.selectedIndex][y].length;i++){
temp1.options[i]=new Option(secondGroup[document.isc.example.options.selectedIndex][y][i].text,secondGroup[document.isc.example.options.selectedIndex][y][i].value)
}
temp1.options[0].selected=true
}

function redirect2(z){
window.location=temp1[z].value
}

//-->
</script>
[code]

Chris Hick
11-05-2010, 08:55 AM
Use:


<script src="dropdown.js" language="Javascript" type="text/javascript"></script>


Make sure your js file is in the same folder as your html file.

abduraooft
11-05-2010, 12:37 PM
Use:


<script src="dropdown.js" language="Javascript" type="text/javascript"></script>


Make sure your js file is in the same folder as your html file.
FYI: The language attribute on <script> in deprecated and it's not needed there.

@Nosdo3: You shouldn't put the script tags inside the external js file.

Nosdo3
11-05-2010, 06:29 PM
Thanks

The .JS file is in the same folder as my HTML and I did remove the script tags What I posted is currently is what I have on my HTML page, I would like to separate the two but cannot figure out what goes in the .JS file and what needs to stay in the HTML.

Any help would be appreciated

Thanks

abduraooft
11-06-2010, 09:11 AM
I have tried the [code]<script type="text/javascript" src="dropdown.js"></script>[code] Your script tag in the html file is OK. You need to put the following in the file dropdown.js

var groups=document.isc.example.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option(" "," ");

group[1][0]=new Option("Customization"," ");
group[1][1]=new Option("Imprinted","47");
group[1][2]=new Option("Blank","46");

group[2][0]=new Option("Customization"," ");
group[2][1]=new Option("Imprinted","12");
group[2][2]=new Option("Blank","11");


group[3][0]=new Option("Customization"," ");
group[3][1]=new Option("Imprinted","87");
group[3][2]=new Option("Blank","86");

var temp=document.isc.stage2


function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
redirect1(0)
}



var secondGroups=document.isc.stage2.options.length
var secondGroup=new Array(groups)
for (i=0; i<groups; i++) {
secondGroup[i]=new Array(group[i].length)
for (j=0; j<group[i].length; j++) {
secondGroup[i][j]=new Array() }}

secondGroup[0][0][0]=new Option(" "," ");
secondGroup[1][0][0]=new Option("Select your Budget "," ");
secondGroup[1][1][0]=new Option(".25 to .99","http://W0Y.COM");
secondGroup[1][1][1]=new Option("$1.00 to $2.99","http://W1Y.com");
secondGroup[1][1][2]=new Option("$3.00 to $4.99","http://W3Y.com");
secondGroup[1][1][3]=new Option("$5.00 and up","http://W5Y.com");


secondGroup[1][2][0]=new Option("Select your Budget"," ");
secondGroup[1][2][1]=new Option(".25 to .99","http://W0N.COM");
secondGroup[1][2][2]=new Option("$1.00 to $2.99","http://W1N.com");
secondGroup[1][2][3]=new Option("$3.00 to $4.99","http://W3N.com");
secondGroup[1][2][3]=new Option("$5.00 and up","http://W5N.com");


secondGroup[2][0][0]=new Option("Select your Budget "," ");
secondGroup[2][1][0]=new Option(".25 to .99","http://P0Y.COM");
secondGroup[2][1][1]=new Option("$1.00 to $2.99","http://P1Y.com");
secondGroup[2][1][2]=new Option("$3.00 to $4.99","http://P3Y.com");
secondGroup[2][1][3]=new Option("$5.00 and up","http://P5Y.com");


secondGroup[2][2][0]=new Option("Select your Budget"," ");
secondGroup[2][2][1]=new Option(".25 to .99","http://P0N.COM");
secondGroup[2][2][2]=new Option("$1.00 to $2.99","http://P1N.com");
secondGroup[2][2][3]=new Option("$3.00 to $4.99","http://P3N.com");
secondGroup[2][2][3]=new Option("$5.00 and up","http://P5N.com");


secondGroup[3][0][0]=new Option("Select your Budget "," ");
secondGroup[3][1][0]=new Option(".25 to .99","http://M0Y.COM");
secondGroup[3][1][1]=new Option("$1.00 to $2.99","http://M1Y.com");
secondGroup[3][1][2]=new Option("$3.00 to $4.99","http://M3Y.com");
secondGroup[3][1][3]=new Option("$5.00 and up","http://M5Y.com");


secondGroup[3][2][0]=new Option("Select your Budget"," ");
secondGroup[3][2][1]=new Option(".25 to .99","http://M0N.COM");
secondGroup[3][2][2]=new Option("$1.00 to $2.99","http://M1N.com");
secondGroup[3][2][3]=new Option("$3.00 to $4.99","http://M3N.com");
secondGroup[3][2][3]=new Option("$5.00 and up","http://M5N.com");



var temp1=document.isc.stage3
function redirect1(y){
for (m=temp1.options.length-1;m>0;m--)
temp1.options[m]=null
for (i=0;i<secondGroup[document.isc.example.options.selectedIndex][y].length;i++){
temp1.options[i]=new Option(secondGroup[document.isc.example.options.selectedIndex][y][i].text,secondGroup[document.isc.example.options.selectedIndex][y][i].value)
}
temp1.options[0].selected=true
}

function redirect2(z){
window.location=temp1[z].value
}

Nosdo3
11-09-2010, 06:11 AM
I initially tried dumping everything between the script tags into a .JS file but when I do it no longer functions. It seems to me that I need to keep some aspect of the javascript in the Html to help control the function? I am probably describing that wrong but on a different project I used javascript on a photo gallery and it had a small snippet of code in the HTML while the bulk was contained in the .js file.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum