Quick and Easy: Use jQuery to Hide a Text Field on a SharePoint Form
This is another post in Paul Galvin’s on-going series on how to use jQuery with SharePoint. If you want to learn more about jQuery, I highly recommend: jQuery in Action by Bear Bibeault and Yehuda Katz.
UPDATE (already!): I did think of a better way to locate the <TR> tag I want to hide and wrote about it here. You may still find this article interesting anyway so I’m leavnig it up.
I want to hide a text field, “Hide Me!” as shown:

The following jQuery does the trick for me:
<script type="text/javascript"> $(function() { $('input[title=Hide Me!]').parent().parent().parent().hide(); }); </script>
The code is saying, “find me all input fields whose title = Hide Me!. Then, get its parent and then next parent and the *next* parent (phew!) and invoke the hide() method on that thing, whatever it happens to be.
I figured out that parent structure by viewing the HTML for the form that SharePoint created as shown:
<TR> <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"> <H3 class="ms-standardheader"> <nobr>Hide Me!</nobr> </H3> </TD> <TD valign="top" class="ms-formbody" width="400px"> <!-- FieldName="Hide Me!" FieldInternalName="Hide_x0020_Me_x0021_" FieldType="SPFieldText" --> <span dir="none"> <input name="ctl00$m$g_bdb23c2c_fde7_495f_8676_69714a308d8e$ctl00$ctl04$ctl02$ctl00$ctl00$ctl04$ctl00$ctl00$TextField" type="text" maxlength="255" id="ctl00_m_g_bdb23c2c_fde7_495f_8676_69714a308d8e_ctl00_ctl04_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00_TextField" title="Hide Me!" class="ms-long" /> <br> </span> </td> </tr>
This picture shows the same, but marked up with the parents:

The first parent (1) is a span tag. Span’s parent (2) is a TD tag and then finally we get to the real parent I want to hide (3) which is the TR tag itself.
This is a pretty terrible approach I think because it’s extremely dependent on the very specific structure of this form. When SharePoint 2010 comes out, this whole structure could change and break this approach. What I really want to do is craft a jQuery selector that is along the lines of “find me all the TR’s (and only TR tags) that have somewhere in their child elements an input field whose title = Hide Me!”. I starting from the bottom and moving up. Assuming I figure this out, I’ll post an updated “quick and easy’ post.
Paul Galvin, Microsoft MVP – SharePoint
Web site: Paul Galvin’s SharePoint Space
Paul is a Solutions Architect currently working most closely with Microsoft Office SharePoint Server 2007. He was recently awarded Microsoft MVP – SharePoint status for his work with the SharePoint community.
- Quick and Easy: Use jQuery to Set A Text Field’s Value on a SharePoint Form
- Quick and Easy: Create Your Own jQuery Sandbox for SharePoint
- Quick and Easy: Use jQuery to Hide a Text Field on a SharePoint Form
- Quick and Easy: A Better Way to Use jQuery to Hide a Text Field on a SharePoint Form
- Securing SharePoint List/Document Library Views Seems (sort of) Possible with jQuery
Paul – I realize that you wrote this to demonstrate the power of JQuery, and you probably already know this, but you can also do this without adding any code too.
You can also hide a field from users by going to the list settings page and allowing management of content types in the Advanced settings section.
Then click on the content type for the list. On the content type settings page, click on the name of the column you want to hide in your forms. Then set the field to be “hidden”. It won’t show up for users to enter or edit information then.
Hi Ricky,
Excellent point you made, however, i wanted to mention a scenario where this isn’t enough based on an exact experience with a client today. I enabled content types as you’d specified and hid the columns they requested. However, they have some custom edit forms they’ve built using sharepoint designer that they want those columns visible for. If i hide it within the content type, it hides for all forms, regardless.
So i needed to use some jquery to only hide it within the new and editforms that the end users use and not affect the custom edit and new forms that they had built for their administrators.
I need to hide- specifically- the Content Type field, which appears by default on all editforms for my list with multiple Content Types.
Since I must allow attachments, I cannot use a custom editform. I have tried various bits of code but nothing works. Help!
to fix the attachments problem with custom edit forms, find line <SharePoint:ItemHiddenVersion
replace ControlMode="New"
it works fine for me, Sharepoint Designer 12.0.6535.5002