Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Nub Question. Referencing an external JS file?

    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]

  • #2
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    Use:
    Code:
    <script src="dropdown.js" language="Javascript" type="text/javascript"></script>
    Make sure your js file is in the same folder as your html file.

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by Chris Hick View Post
    Use:
    Code:
    <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.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    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
    Code:
    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
    }
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks for the reply

    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •