Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-06-2004, 12:11 AM   PM User | #1
doogie352
New to the CF scene

 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
doogie352 is an unknown quantity at this point
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>
doogie352 is offline   Reply With Quote
Old 05-06-2004, 07:37 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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)
Philip M is offline   Reply With Quote
Old 05-08-2004, 09:48 PM   PM User | #3
doogie352
New to the CF scene

 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
doogie352 is an unknown quantity at this point
Follow Up

I have tried changing every variable, etc to no avial. Any other ideas?
doogie352 is offline   Reply With Quote
Old 05-08-2004, 10:37 PM   PM User | #4
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
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.
Willy Duitt is offline   Reply With Quote
Old 05-09-2004, 05:37 PM   PM User | #5
doogie352
New to the CF scene

 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
doogie352 is an unknown quantity at this point
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
}
doogie352 is offline   Reply With Quote
Old 05-09-2004, 05:47 PM   PM User | #6
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
You have multiple redirect and go functions.
Willy Duitt is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:35 PM.


Advertisement
Log in to turn off these ads.