Results 1 to 3 of 3

Thread: Using array in js file

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954

    Using array in js file

    I have a webpage that has a combo box. I would like to have a user select something out of the combo box and have the onChange event occur. I would like to then have a script run that will read from a text file (server side) and according to what they selected it would file in another combo box. I know with server/client side stuff this gets messy but is it possible to do it this way? If so how, I can do it be hardcoding the values in but have had no luck when trying to access the file. Should put it into a js file? Here is the code:

    <script language="JavaScript">
    <!--

    /*
    Double Combo Script Credit
    By JavaScript Kit (www.javascriptkit.com)
    Over 200+ free JavaScripts here!
    */

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

    group[1][0]=new Option("JavaScript Kit","http://javascriptkit.com")
    group[1][1]=new Option("News.com","http://www.news.com")
    group[1][2]=new Option("Wired News","http://www.wired.com")

    group[2][0]=new Option("CNN","http://www.cnn.com")
    group[2][1]=new Option("ABC News","http://www.abcnews.com")

    group[3][0]=new Option("Hotbot","http://www.hotbot.com")
    group[3][1]=new Option("Infoseek","http://www.infoseek.com")
    group[3][2]=new Option("Excite","http://www.excite.com")
    group[3][3]=new Option("Lycos","http://www.lycos.com")

    var temp=document.frmA192A.cboVendor

    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
    }

    function go(){
    location=temp.options[temp.selectedIndex].value
    }


    </script>
    //-->

    and here is the html that ref's it:

    <select name="cboOffice" size="1" onChange="redirect(this.options.selectedIndex)">

  2. #2
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    Are you currently using it from a JS file??

  3. #3
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    Put this in a file and name it 'array.js'
    Code:
    /* 
    Double Combo Script Credit 
    By JavaScript Kit (www.javascriptkit.com) 
    Over 200+ free JavaScripts here! 
    */ 
    
    var groups=document.frmA192A.cboOffice.options.length 
    var group=new Array(groups) 
    for (i=0; i<groups; i++) 
    group[i]=new Array() 
    
    group[1][0]=new Option("JavaScript Kit","http://javascriptkit.com") 
    group[1][1]=new Option("News.com","http://www.news.com") 
    group[1][2]=new Option("Wired News","http://www.wired.com") 
    
    group[2][0]=new Option("CNN","http://www.cnn.com") 
    group[2][1]=new Option("ABC News","http://www.abcnews.com") 
    
    group[3][0]=new Option("Hotbot","http://www.hotbot.com") 
    group[3][1]=new Option("Infoseek","http://www.infoseek.com") 
    group[3][2]=new Option("Excite","http://www.excite.com") 
    group[3][3]=new Option("Lycos","http://www.lycos.com") 
    
    var temp=document.frmA192A.cboVendor 
    
    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 
    } 
    
    function go(){ 
    location=temp.options[temp.selectedIndex].value 
    }
    doesn't need the script tags!

    then use
    Code:
    <script language="javascript" src="array.js"></script>
    to include the javascript in your html file!

    does this help or is this what you've got already, I didn't really grasp what you was on about!


Posting Permissions

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



Click Here to Expand Forum to Full Width