2

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>
SP.Developer
  • 55
  • 3
  • 7

3 Answers3

2

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>
Brandon Boone
  • 16,281
  • 4
  • 73
  • 100
  • 2
    PeopleEditor is a Sharepoint .NET control. It's the big giant mess of html that has like 4 inputs, a textarea, contentEditable div, some image buttons... all wrapped in a couple tables and spans... it's not fun. – James Montagne Jun 22 '11 at 17:14
  • @kingjiv - doesn't look like it since this code is NASTY!!! I can't imagine why in the world you would need input names over 115 characters! Not to mention the all CAPS html nodes... – Brandon Boone Jun 22 '11 at 17:18
1

PeopleEditor is pretty complicated and annoying. There are multiple components you need to deal with in order to disable it. In IE there is a contentEditable div which is the main input which you can type into. You also have the image buttons which have an onclick to deal with. Then in non-IE browsers I believe it uses the textarea.

You will need to do something like this (untested, you may need to tweak it):

$("span[id$='_UserField']").find(":input").val("").attr("disabled",true); 

The above will clear and disable all input fields used by the control (including textarea).

Then you need to deal with the content editable div. I am unsure if you can disable it or if you need to change the contentEditable property like so:

$("div[id$='_UserField_upLevelDiv']").text("").attr("contentEditable",false);

And finally, the images. The images are wrapped in an a tag with an onclick. My suggestion here is to just hide them like this:

$("span[id$='_UserField']").find("img").hide();

Hope that helps. If you can get away with it, it's much easier to just hide the whole thing.

James Montagne
  • 77,516
  • 14
  • 110
  • 130
  • 1
    +1, the people picker is a nightmare. I have a [related post](http://stackoverflow.com/questions/4157386/retrieve-email-address-from-sharepoint-people-picker-using-javascript/4158850#4158850) which may help. – Kit Menke Jun 22 '11 at 19:06
0

Another option would be using SPUtility.js (full disclosure, I maintain this open source library). It depends on Prototype.js so you may not be interested since you are using jQuery.

It supports hiding and/or disabling many different field types.. including people pickers:

// make a people field read only
SPUtility.GetSPField('Assigned To').MakeReadOnly();
// hide the people field
SPUtility.GetSPField('Assigned To').Hide();
Kit Menke
  • 7,046
  • 1
  • 32
  • 54