RachVG
05-13-2008, 01:18 PM
Hi,
I've got a perfectly working double combobox script, however now I'm wanting to put another two on the same page to offer the same options for three different publications.
Basically, its for a newspaper's adsonline service where customers can place birthday announcements etc via the website. The first combo box has birthday, births, weddings, engagements, anniversaries etc, and the second box has specific category information based on the first choice - 1st, 18th, 21st etc for birthdays, golden, ruby, diamond etc for anniversaries. When the second is selected, the onchange takes the user to the booking page for their selected option.
We run this service for two newspapers, and also the option to place the advert in both publications - therefore, it needs to be repeated three times, but where the links in publication #1 take the user to example.com, in publication #2 they'd go to example.net and in publication #3 they'd go to example.org.
I've searched high and low found helpful posts showing me how to get two working double combo boxes on the same page, but they don't use a link with the second box. If I had to put a "go" button on, I would, but I'd rather stick with using onchange if possible. Either way, it is important that the options in the second box contain the URL so that the form will take the user to the relevant page they have selected.
Currently it displays as
Publication #1: [Category1] [Subcategory1]
I need to modify it so that I can triplicate it on the same page, so that it will show as:
Publication #1: [Category1] [Subcategory1]
Publication #2: [Category2] [Subcategory2]
Publication #3: [Category3] [Subcategory3]
I currently have the code for each publication saved in individual documents for ease of working, and individually, they work great. My main question now is how to put them together on one document so that they will work well together. The code as it stands is obviously the form part followed by the script part, and I know that just pasting the other two publications after this first one won't work as form-script-form-script-form-script is a big no-no if I want it to work correctly.
... as a complete js newbie I just need a quick bump in the right direction in terms of where to paste which parts of the code for publications 2 and 3!
This is a shortened version of the script I have at the moment (the full thing has 14 options in box one, and 34 in the largest subcatgeory in box two.) Apologies if this is too much unncessary info, I have a tendancy to overexplain instead of running the risk of missing out details.
<form name="pressnotices">
Choose Category:
<select name="cat1" id="cat1" size="1" onChange="redirect(this.options.selectedIndex,'subcat1')">
<option selected="selected">Please Select</option>
<option>Acknowledgements </option>
<option>Birthdays </option>
<option>Births & Adoptions </option>
</select>
</p>
<p align="left">Choose Subcategory:
<select name="subcat1" id="subcat1" size="1" onchange="go()">
<option value="">Select above first</option>
</select>
</p>
<script>
<!--
var groups=document.pressnotices.cat1.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()
group[0][0]=new Option("Select above first","")
group[1][0]=new Option("--Acknowledgements --","")
group[1][1]=new Option("Acknowledgement","http://www.example.com")
group[2][0]=new Option("--Birthdays --","")
group[2][1]=new Option("1st Birthday","http://www.example.com")
group[2][2]=new Option("18th Birthday","http://www.example.com")
group[2][3]=new Option("21st Birthday","http://www.example.com")
group[3][0]=new Option("--Births --","")
group[3][1]=new Option("Births","http://www.example.com")
group[3][2]=new Option("Adoptions","http://www.example.com")
function redirect(x,elem){
temp = document.pressnotices[elem];
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>
</form>
I've got a perfectly working double combobox script, however now I'm wanting to put another two on the same page to offer the same options for three different publications.
Basically, its for a newspaper's adsonline service where customers can place birthday announcements etc via the website. The first combo box has birthday, births, weddings, engagements, anniversaries etc, and the second box has specific category information based on the first choice - 1st, 18th, 21st etc for birthdays, golden, ruby, diamond etc for anniversaries. When the second is selected, the onchange takes the user to the booking page for their selected option.
We run this service for two newspapers, and also the option to place the advert in both publications - therefore, it needs to be repeated three times, but where the links in publication #1 take the user to example.com, in publication #2 they'd go to example.net and in publication #3 they'd go to example.org.
I've searched high and low found helpful posts showing me how to get two working double combo boxes on the same page, but they don't use a link with the second box. If I had to put a "go" button on, I would, but I'd rather stick with using onchange if possible. Either way, it is important that the options in the second box contain the URL so that the form will take the user to the relevant page they have selected.
Currently it displays as
Publication #1: [Category1] [Subcategory1]
I need to modify it so that I can triplicate it on the same page, so that it will show as:
Publication #1: [Category1] [Subcategory1]
Publication #2: [Category2] [Subcategory2]
Publication #3: [Category3] [Subcategory3]
I currently have the code for each publication saved in individual documents for ease of working, and individually, they work great. My main question now is how to put them together on one document so that they will work well together. The code as it stands is obviously the form part followed by the script part, and I know that just pasting the other two publications after this first one won't work as form-script-form-script-form-script is a big no-no if I want it to work correctly.
... as a complete js newbie I just need a quick bump in the right direction in terms of where to paste which parts of the code for publications 2 and 3!
This is a shortened version of the script I have at the moment (the full thing has 14 options in box one, and 34 in the largest subcatgeory in box two.) Apologies if this is too much unncessary info, I have a tendancy to overexplain instead of running the risk of missing out details.
<form name="pressnotices">
Choose Category:
<select name="cat1" id="cat1" size="1" onChange="redirect(this.options.selectedIndex,'subcat1')">
<option selected="selected">Please Select</option>
<option>Acknowledgements </option>
<option>Birthdays </option>
<option>Births & Adoptions </option>
</select>
</p>
<p align="left">Choose Subcategory:
<select name="subcat1" id="subcat1" size="1" onchange="go()">
<option value="">Select above first</option>
</select>
</p>
<script>
<!--
var groups=document.pressnotices.cat1.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()
group[0][0]=new Option("Select above first","")
group[1][0]=new Option("--Acknowledgements --","")
group[1][1]=new Option("Acknowledgement","http://www.example.com")
group[2][0]=new Option("--Birthdays --","")
group[2][1]=new Option("1st Birthday","http://www.example.com")
group[2][2]=new Option("18th Birthday","http://www.example.com")
group[2][3]=new Option("21st Birthday","http://www.example.com")
group[3][0]=new Option("--Births --","")
group[3][1]=new Option("Births","http://www.example.com")
group[3][2]=new Option("Adoptions","http://www.example.com")
function redirect(x,elem){
temp = document.pressnotices[elem];
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>
</form>