SP.Developer
SP.Developer

Reputation: 55

Enable disable a radio buttons from bunch of radio buttons pending on option selected in drop down box

Dropdown 1 "Type of Notifications" options Employee/Contractor Leave of Absence, Employee/Contractor Return from Leave of Absence, Change of Supervisor and few more

Radio Button 1 column name Division( it to be disabled for options provided above)

Radio Button 2 column name Country( it should be enabled for every option selected in drop down)

<script language="JavaScript">
$('.ms-RadioText').change(function(){
        var opt = $(this).val();
        if(opt == 'Employee/Contractor Leave of Absence' || opt == 'Employee/Contractor Return from Leave of Absence' || opt == 'Change of Supervisor')
       {
            $('input:radio').attr('disabled', 'disabled');
        }
     else
         {
            $('input:radio').removeAttr('disabled');
         }
    });
     </script>

Using above code I could disable every Radio Button in page

$('.ms-RadioText').change(function(){
    var opt = $(this).val();
    if(opt == 'Employee/Contractor Leave of Absence' || opt == 'Employee/Contractor Return from Leave of Absence' || opt == 'Change of Supervisor' || opt == 'Separation from Abbott or GPRD/Clinical')
   {
        $('input[name='Division']:radio').attr('disabled', 'disabled');
    }
 else
     {
        $('input[name='Division']:radio').removeAttr('disabled');
     }
});

Currently working with above code but not moving forward

Any insight highly appreciated

Source code

<TR>
        <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
        <nobr>Type of Notification</nobr>
    </H3></TD>
        <TD valign="top" class="ms-formbody" width="400px">
        <!-- FieldName="Type of Notification"
             FieldInternalName="Type_x0020_of_x0020_Notification"
             FieldType="SPFieldChoice"
          -->
            <span dir="none"><select name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl03$ctl00$ctl00$ctl04$ctl00$DropDownChoice" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl03_ctl00_ctl00_ctl04_ctl00_DropDownChoice" title="Type of Notification" class="ms-RadioText">
                           <option value="Select One">Select One</option>
<option value="New Employee/Contractor">New Employee/Contractor</option>
<option value="Employee/Contractor Position Change">Employee/Contractor Position Change</option>
    <option value="Contractor to Employee">Contractor to Employee</option>                          <option value="Employee/Contractor Leave of Absence">Employee/Contractor Leave of Absence</option>
<option value="Employee/Contractor Return from Leave of Absence">Employee/Contractor Return from Leave of Absence</option>
<option value="Name Change">Name Change</option>                            <option selected="selected" value="Change of Supervisor">Change of Supervisor</option>



                        </select><br></span>                    
        </TD>
    </TR>


    <TR>
        <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
        <nobr>Division</nobr>
    </H3></TD>
        <TD valign="top" class="ms-formbody" width="400px">
        <!-- FieldName="Division"
             FieldInternalName="Division"
             FieldType="SPFieldChoice"
          -->
            <span dir="none"><table cellpadding="0" cellspacing="1">
                            <tr>
                                <td><span class="ms-RadioText" title="Affiliate"><input id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl07_ctl00_ctl00_ctl04_ctl00_ctl00" type="radio" name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl07$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl00" /><label for="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl07_ctl00_ctl00_ctl04_ctl00_ctl00">Affiliate</label></span></td>
                            </tr><tr>
                                <td><span class="ms-RadioText" title="GPRD"><input id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl07_ctl00_ctl00_ctl04_ctl00_ctl01" type="radio" name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl07$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl01" checked="checked" /><label for="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl07_ctl00_ctl00_ctl04_ctl00_ctl01">GPRD</label></span></td>
                            </tr>
                        </table></span>
            Division of the Requestor

        </TD>
    </TR>


<TR>
        <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
        <nobr>Are you Manager</nobr>
    </H3></TD>
        <TD valign="top" class="ms-formbody" width="400px">
        <!-- FieldName="Are you Manager"
             FieldInternalName="Are_x0020_you_x0020_Manager"
             FieldType="SPFieldChoice"
          -->
            <span dir="none"><table cellpadding="0" cellspacing="1">
                            <tr>
                                <td><span class="ms-RadioText" title="Yes"><input id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl38_ctl00_ctl00_ctl04_ctl00_ctl00" type="radio" name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl38$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl00" checked="checked" /><label for="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl38_ctl00_ctl00_ctl04_ctl00_ctl00">Yes</label></span></td>
                            </tr><tr>
                                <td><span class="ms-RadioText" title="No"><input id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl38_ctl00_ctl00_ctl04_ctl00_ctl01" type="radio" name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl38$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl01" /><label for="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl38_ctl00_ctl00_ctl04_ctl00_ctl01">No</label></span></td>
                            </tr>
                        </table></span>
            Authorisation to approve

        </TD>
    </TR>

Upvotes: 0

Views: 738

Answers (3)

GregL
GregL

Reputation: 38121

When using jQuery with .NET controls, a great technique to use when trying to select .NET server controls (like textboxes, radio buttons, etc) is to use the "attribute ends with" selector in jQuery, which is [attribute$=some_text]. Since the IDs that .Net generates almost always end with the ID that you specify, then you can use [id$=Division]. If you then couple that with a more specific, clearer selector for efficiency, you might try, in your case:

$('.ms-RadioText').change(function(){
    var opt = $(this).val();
    var $radio = $('input:radio[id$=Division]'); // keep the radio button as a local variable
    if(opt == 'Employee/Contractor Leave of Absence' || opt == 'Employee/Contractor Return from Leave of Absence' || opt == 'Change of Supervisor' || opt == 'Separation from Abbott or GPRD/Clinical')
   {
        $radio.attr('disabled', 'disabled');
    }
 else
     {
        $radio.removeAttr('disabled');
     }
});

Note I used the convention when using variables to store jQuery objects of prefixing their name with "$" to make it clear it is a jQuery object.

Upvotes: 1

c3rin
c3rin

Reputation: 1917

For this line (and the other line that uses the same jQuery selector):

 $('input[name='Division']:radio').attr('disabled', 'disabled');

When using a selector with quotes in it, they need to be different than the quotes used to define the string. You use single quotes to define the string so use double quotes around the attribute value "Division".

 $('input[name="Division"]:radio').attr('disabled', 'disabled');

Upvotes: 1

shernshiou
shernshiou

Reputation: 518

I think you need to change

$('input[name='Division']:radio')

to something like

$('input[name='+Division+']:radio')

p/s: I am assuming Division is a variable

Upvotes: 0

Related Questions