I know that I am probably coding it weird, and that's why I raised the issue. Posting the full code that I have here will probably confuse you more, so let me try to clarify what I am trying to do....
I have options whose selection state depends on the state of selection in another option list. (i.e. a multiple choice menu. This is not an issue if you don't allow multiple choices, as you always do get the last selected value.
This is the way php expects the data to be in order to pass products as an array in HTTP_POST_VARS To the next page.
<select multiple name="protocols[]" >
<OPTION value=Alliance_Product1 onClick="ClickProtocol()"> Alliance_Protocol1
<OPTION value=Alliance_Product1 onClick="ClickProtocol()"> Alliance_Protocol2
<OPTION value=Alliance_Product2 onClick="ClickProtocol()"> Alliance_Protocol3
<OPTION value=Alliance_Product2 onClick="ClickProtocol()"> Alliance_Protocol4
<OPTION value=Alliance_Product3 onClick="ClickProtocol()"> Alliance_Protocol4
<OPTION value=Berlex_Product1 onClick="ClickProtocol()"> Berlex_Protocol1
</select>
I am unsure of how to refer to this option element array in my javascript. If I set select option array name as "protocols" instead of "protocols[]" this works :
<script language="JavaScript">
// This function processes a click on the protocol element to update
// the list of selected protocol elements.
function ClickProtocol() {
var theProtocols = document.MYFORM.protocols;
// Reset the selected protocols....
document.MYFORM.selectedprotocols.value = "";
// Walk through all the protocols, adding the selected ones to
// selecteprotocols value.
for(theProtocolCounter=0;theProtocolCounter<theProtocols.options.length; theProtocolCounter++) {
// If the protocol is selected add it to the selectedprotocols list...
if (theProtocols.options[theProtocolCounter].selected) {
document.MYFORM.selectedprotocols.value = document.MYFORM.selectedprotocols.value + theProtocols.options[theProtocolCounter].text + ",";
}
}
}
</SCRIPT>
However I don't know how to refer to the protocols[] array from my javascript.
BTW Using the onchange is probably better than doing an onclick for my case, since I am only interested in the selection states changing.
Thank in advance for any help or advice.
Anurag