...

View Full Version : Running SAME script twice on one page



doogie352
05-06-2004, 01:11 AM
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>

Philip M
05-06-2004, 08:37 PM
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)

doogie352
05-08-2004, 10:48 PM
I have tried changing every variable, etc to no avial. Any other ideas?

Willy Duitt
05-08-2004, 11:37 PM
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.

doogie352
05-09-2004, 06:37 PM
:confused:

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
}

Willy Duitt
05-09-2004, 06:47 PM
You have multiple redirect and go functions.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum