PDA

View Full Version : Multiple double combo boxes on one form


mengbers
08-12-2002, 04:31 PM
Working on a web page and I need multiple double combo boxes in order to allow someone to submit multiple options in a way usable for the person recieving the form.

Whenever I try to enter the second set of combo boxes, the first one links up with the second combo box options.

Been searching for a while to find the solution but no luck... to see what I've done go to: www.trinity-baptist.ca/visa.html (http://www.trinity-baptist.ca/visa.html)

How do I keep the combo boxes linked to each other when there are multiple sets of them? The other way I imagined it might work is to have all the combo boxes feed off of one set of menus and just display the choices multiple times... I'm open to suggestions.

Thanks,

Mike Engbers

ShriekForth
08-12-2002, 09:23 PM
The way I would do it would be to pass along with the selected index, the name of the field you want the sub menu to populate with. Right now you have the array declared twice, as well as the redirect function. The second declaration is the one that will be used, that is why it always populates the second box, as it was declared last. So...

Remove the extra script declarations, and move the only/final copy to the bottom of the page, just before you close the body will work. Then use this function instead of the one you have...

function redirect(x, item){
eval ('temp=document.dform.' + item)
mct=temp.length-1
for (m=0 ;m>mct ;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
}

This will take a second parameter to let the fucntion know which form item you want to populate.

This means that you will have to modify category, and category 2 to pass the related account box name, like so

<select name="category" size="1" onChange="redirect(this.options.selectedIndex, 'account')">
<select name="category2" size="1" onChange="redirect(this.options.selectedIndex, 'account2')">

Any additional selections would be handled the same way. You should also close the <select > objects you have on account, and account2, just to keep everything clear for you and some browsers.

ShriekForth