The following post applies to WSS 3.0 or MOSS 2007:

Scenario: When you click the “New” button on a List to add a new item to the list, you want to hide some of the fields displayed to the user. This is useful when you have fields that you only want accessible to the user who has “Add” privileges (to add a new item). I found this in a post from a blog about a year ago. Very useful.

Solution: This can be performed in SharePoint Designer 2007. I recommend that you make a copy of your NewForm.aspx page and re-name it as a backup in case you mess this up. Then you can always save over it and try again.

Scroll down the NewForm.aspx page and look for the end of the </table> tag at the end of the </WebPart>.

#### INSERT javascript after these lines ###################
</WebPart>
</WebPartPages:ListFormWebPart>
</ZoneTemplate></WebPartPages:WebPartZone>
<IMG SRC=”/_layouts/images/blank.gif” width=590 height=1 alt=”">
</td>
</tr>
</table>
################################################

##### HERE IS YOUR JAVASCRIPT CODE TO ADD #############

<script language=”javascript” type=”text/javascript”>
_spBodyOnLoadFunctionNames.push(”hideRows”);
function hideRows()
{
var pageTables = document.getElementsByTagName(’table’);
var cName = null;
var formTables = null;
for(var i=0; i < pageTables.length; i++){
cName = pageTables[i].className;
if (cName == “ms-formtable”){
formTables = pageTables[i];
}
}
var rows = formTables.rows;
rows[rows.length-2].style.display = “none”;
rows[rows.length-3].style.display = “none”;

}
</script>

Save this and you will see a row disappear from the NewForm.aspx page.

Note: You will need to have JavaScript enable on the browser and make sure that the fields you are hiding are not “Required”. To hide more fields, just add another line in the sequence of the last line: rows[rows.length-3].style.display = “none”;

Tags Categories: JavaScript, SharePoint Posted By: Clinton Daniel
Last Edit: 16 Feb 2009 @ 09 41 AM

E-mailPermalinkComments (7)
\/ More Options ...
Change Theme...
  • Users » 2
  • Posts/Pages » 16
  • Comments » 41
Change Theme...
  • VoidVoid
  • LifeLife « Default
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LiteLight
  • No Child Pages.