Joined Radio Buttons - Dynamic ID

Discussion in 'JavaScript' started by balddog, Mar 8, 2008.

  1. #1
    I am a ColdFusion developer. I have limited skill in JavaScript, so I need your help. I found the code that I need to get the results I want, however, I need to make some minor modifications that I don't know how to do.

    The following JS connects two radio buttons so that if one is selected, the "joined" radio button is automatically selected. I am developing for a conference where the registrant can select multiple workshops, however, some of them are part 1 of 2, part 2 of 2. The two workshops would need to be tied together so that if they select one, the other is automatically selected. I dynamically generate the workshop form fields. In my database, I have the "mate" designated for each record that matches. I don't know how to tie this in to the JS variables. I have the basic skeleton of code. I found the example below which seems to be what I'm wanting to do. The difference is that the id's are hard-coded where mine will be dynamic.

    <script language="javascript">
    function getObject(obj){if(document.getElementById){return document.getElementById(obj);}else{if(document.all){return document.all[obj];}}}
    function radioBtnGroupChanged(obj){
    switch(obj.id) {
    case "rbA1":
    getObject('rbB2').checked = true;
    break;
    case "rbA2":
    getObject('rbB1').checked = true;
    break;
    }
    }
    </script>

    <input type="radio" id="rbA1" name="rbA" onclick="radioBtnGroupChanged(this);" /><br />
    <input type="radio" id="rbA2" name="rbA" onclick="radioBtnGroupChanged(this);" />
    <br />
    <br />
    <br />
    <input type="radio" id="rbB1" name="rbB" /><br />
    <input type="radio" id="rbB2" name="rbB" />

    Instead, I have one radio field that turns into multiple fields as it is output from a query:

    <cfoutput query="workshops">
    <input type="radio" name="session#variables.name#1" value="#workshops.workshopid#" id="#workshops.mate#" onclick="radioBtnGroupChanged(this);">
    </cfoutput>

    I really appreciate any help. This is the final item on my punch list - saved the best for last!
     
    balddog, Mar 8, 2008 IP