Search code examples
jquerysharepointsharepoint-2007

Need jquery code to disable Drop downs and people pickers when a option in dropdown is selected in sharepoint


I am working with moss 2007. I created a drop down column in which has 3 options. If option1 and option 2 are selected the Dropdowns and People pickers should be disabled and if option 3 selected the Dropdowns and People picker columns should be enabled. I provided the page source code, could someone help me out with this with some coding since i am newbie to jquery.

<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$ctl07$ctl00$ctl00$ctl04$ctl00$DropDownChoice" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl07_ctl00_ctl00_ctl04_ctl00_DropDownChoice" title="Type of Notification" class="ms-RadioText">
        <option selected="selected" value="Select One">Select One</option>

        <option value="Option1">Option1</option>
        <option value="Option2">Option2</option>
                  <option value="Option3">Option3</option>

    </select><br></span></TD></TR>
<TR>
        <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
        <nobr>Functional Team</nobr>
    </H3></TD>
        <TD valign="top" class="ms-formbody" width="400px">
        <!-- FieldName="Functional Team"
             FieldInternalName="Mytest"
             FieldType="SPFieldCascadingDropDownListFieldWithFilter"
          -->
            <span dir="none">
        <select name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl16$ctl00$ctl00$ctl04$ctl00$ctl00$Functional Team" onchange="javascript:setTimeout('WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl16$ctl00$ctl00$ctl04$ctl00$ctl00$Functional Team&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))', 0)" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl16_ctl00_ctl00_ctl04_ctl00_ctl00_Functional Team" title="Functional Team Parent" class="ms-input">
    <option selected="selected" value="">Please select an Item</option>
    <option value="Test">Test</option>
    <option value="Other">Other</option> 
</select></span></TD></TR>
<TR>
        <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
        <nobr>Therapeutic Area</nobr>
    </H3></TD>
        <TD valign="top" class="ms-formbody" width="400px">
        <!-- FieldName="Therapeutic Area"
             FieldInternalName="Therapeutic_x0020_Area"
             FieldType="SPFieldChoice"
          -->
            <span dir="none"><select name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl17$ctl00$ctl00$ctl04$ctl00$DropDownChoice" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl17_ctl00_ctl00_ctl04_ctl00_DropDownChoice" title="Therapeutic Area" class="ms-RadioText">
    <option selected="selected" value="Select One">Select One</option>
    <option value="Anti-Infective">Anti-Infective</option>
    <option value="Other">Other</option> 
</select><br></span></TD>   </TR>

<TR>
        <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
        <nobr>Admin Name</nobr>
    </H3></TD>
        <TD valign="top" class="ms-formbody" width="400px">
        <!-- FieldName="Admin Name"
             FieldInternalName="Admin_x0020_Name"
             FieldType="SPFieldUser"
          -->
            <span dir="none">
        <input name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$HiddenUserFieldValue" type="hidden" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_HiddenUserFieldValue" />
        <span id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField" class="ms-usereditor" NoMatchesText="&lt;No Matching Names>" MoreItemsText="More Names..." RemoveText="Remove" value="" allowEmpty="1" ShowEntityDisplayTextInTextBox="0" EEAfterCallbackClientScript=""><input name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField$hiddenSpanData" type="hidden" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_hiddenSpanData" /><input name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField$OriginalEntities" type="hidden" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_OriginalEntities" value="&lt;Entities />" /><input name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField$HiddenEntityKey" type="hidden" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_HiddenEntityKey" /><input name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField$HiddenEntityDisplayText" type="hidden" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_HiddenEntityDisplayText" /><table id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_OuterTable" class="ms-usereditor" cellspacing="0" cellpadding="0" border="0" style="border-collapse:collapse;">
    <tr valign="bottom">
        <td valign="top" style="width:90%;"><table cellpadding="0" cellspacing="0" border="0" style="width:100%;table-layout:fixed;">
            <tr>
                <td><div id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_upLevelDiv" TabIndex="0" onFocusIn="this._fFocus=1;saveOldEntities('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_upLevelDiv')" onClick="onClickRw(true, true);" onChange="updateControlValue('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField')" onFocusOut="this._fFocus=0;" onPaste="dopaste();" AutoPostBack="0" class="ms-inputuserfield" onDragStart="canEvt(event);" onKeyup="return onKeyUpRw('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField');" onCopy="docopy();" onBlur="updateControlValue('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField')" Title="People Picker" onKeyDown="return onKeyDownRw(this, 'ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField', 3, true, event);" contentEditable="true" style="width: 100%; word-wrap: break-work;overflow-x: hidden; background-color: window; color: windowtext;" name="upLevelDiv"></div><textarea name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField$downlevelTextBox" rows="1" cols="20" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_downlevelTextBox" class="ms-input" onKeyDown="return onKeyDownRw(this, 'ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField', 3, true, event);" onKeyUp="onKeyUpRw('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField');" Title="People Picker" AutoPostBack="0" style="width:100%;display: none;position: absolute; "></textarea></td>
            </tr>
        </table></td><td align="right" valign="top" nowrap="true" style="padding-left:5px;"><a id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_checkNames" title="Check Names" onclick="var arg=getUplevel('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField');var ctx='ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField';EntityEditorSetWaitCursor(ctx);WebForm_DoCallback('ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField',arg,EntityEditorHandleCheckNameResult,ctx,EntityEditorHandleCheckNameError,true);return false;" href="javascript:"><img title="Check Names" src="/_layouts/images/checknames.gif" alt="Check Names" style="border-width:0px;" /></a>&nbsp;<a id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_browse" accesskey="B" title="Browse" onclick="__Dialog__ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField(); return false;" href="javascript:"><img title="Browse" src="/_layouts/images/addressbook.gif" alt="Browse" style="border-width:0px;" /></a></td>
    </tr><tr>
        <td colspan="3"><span id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_errorLabel" class="ms-error"></span></td>
    </tr>
</table></span>
    </span>


        </TD>
    </TR>

Solution

  • Not sure how to disable your People Picker (didn't see/understand from your html). But this will take care of the drop downs.

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script>
    <script type="text/javascript">
        $(function(){
            $('select[title="Type of Notification"]').change(function(){
                if($(this).val() == "Option1" || $(this).val() == "Option2")
                {
                    $('select').not(this).attr('disabled', 'disabled');
                }else if($(this).val() == "Option3"){
                    $('select').not(this).removeAttr('disabled');
                }
            });
        });
    </script>