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
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Running SAME script twice on one page

    This is probably an easy question, but I have tried for three hours to figure it out with no luck.

    I am trying to use the Double Combo script (http://javascriptkit.com/script/cut183.shtml). The script runs great, but I need it to run twice within the same form on the same page. This causes any selection in either of the main categories to change the sub category in only the second set of boxes. I have changed the names of both the main and subcategories to no avail. I am guessing I have to make a change in the array, but I can't figure out what. The relevant code is shown below. I did not post the whole thing since it is over 800 lines. Any assistance would be greatly appreciated.




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



    [the options for the main box are here]



    <script>

    <!--

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

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



    [the arrays are here]



    var temp=document.form_216_1.reason_subsec

    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>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Thisa is a common problem.

    Change all the function and variable names in the second script to something different - e.g. groupsB

    (and semi-colons at the line ends are supposed to be obligatory)

  • #3
    New to the CF scene
    Join Date
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Follow Up

    I have tried changing every variable, etc to no avial. Any other ideas?

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by doogie352
    I have tried changing every variable, etc to no avial. Any other ideas?
    Try again, being a wee bit more careful and/or use the forums search feature to find how others resolved the same issue.

  • #5
    New to the CF scene
    Join Date
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question One more try



    Thanks for the suggestions so far. Despite many hours of trying, I have had no luck. I have copied the code that I have changed. Yet I still have the same problem. Whenever I change the primary value in either drop down list (A or B for this discussion), the secondary value in B changes. It seems to ignore the fact that there is a dependent list within group A.

    I have a background in basic web development, but I am just learning scripting. Any assistance would be appreciated as I have a presentation to give in the morning.

    Group A

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

    group[0][0]=new Option("101","101")
    group[0][1]=new Option("102","102")

    <snip>

    group[43][0]=new Option("N/A","N/A")
    group[44][0]=new Option("N/A","N/A")

    var temp=document.form_216_1.reason_subsec

    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
    }

    Group B
    var groupsb=document.form_216_1.written_section.options.length
    var group2=new Array(groupsb)
    for (j=0; j<groupsb; j++)
    group2[j]=new Array()

    group2[0][0]=new Option("101","101")
    group2[0][1]=new Option("102","102")

    <snip>

    group2[43][0]=new Option("N/A","N/A")
    group2[44][0]=new Option("N/A","N/A")

    var temp2=document.form_216_1.written_subsec

    function redirect(y){
    for (n=temp2.options.length-1;n>0;n--)
    temp2.options[n]=null
    for (j=0;j<group2[y].length;j++){
    temp2.options[j]=new Option(group2[y][j].text,group2[y][j].value)
    }
    temp2.options[0].selected=true
    }

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

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You have multiple redirect and go functions.


  •  

    Posting Permissions

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