NEWS

Tuesday, August 3, 2010

Hiding field in SharePoint through JavaScript

Many times we require to hide specific field in new form, disp form and edit form. This time we will do it with the help of javascript. We can do the same thing with the help of SharePoint API. However we will cover here that how to achieve the same with the help of JavaScript.




Let us go to calendar and click on new. You will now be on Newform.aspx. We can see here one field named “WorkSpace”. If we don’t want user to create any workspace here, then we can hide this field with the help of JavaScript code.

To hide a specific field, insert one content editor web part on the page and then just copy and paste the following code. Insert this web part below the new form web part.
 
<script type="text/javascript">

function HideField(title){

var header_h3=document.getElementsByTagName("h3") ;



for(var i = 0; i <header_h3.length; i++)

{

var el = header_h3[i];

var foundField ;

if(el.className=="ms-standardheader")

{

for(var j=0; j<el.childNodes.length; j++)

{


if(el.childNodes[j].innerHTML == title || el.childNodes[j].nodeValue == title)

{


var elRow = el.parentNode.parentNode ;

elRow.style.display = "none"; //and hide the row

foundField = true ;

break;

}

}


}

if(foundField)

break ;

}

}



HideField("Workspace");



</script>

Limiting the number of responses in survey

Many times we require limiting number of responses from survey. However SharePoint does not provide us with the facility to limit the number of responses.




Ok, then how to achieve this? Here we go, follow these simple steps and you are good to go.



(1) Write one web part and write one code which checks for the total responses for specific survey. Add this web part on NewForm.aspx and overview.aspx, all responses and graphical summary of the survey. You get NewForm.aspx when you click on respond to the survey button.



(2) Write down simple code, check URL, if NewForm word exist, then just count the total number of item in survey and if it exceeds let’s say 30 responses, and then redirect back to Source parameter.



(3) If in URL overview, allitems or summary exist, just count the total number of item in survey and if it exceeds let’s say 30 responses then write a statement saying you are not allowed to respond because it has already reached to the maximum responses.

How to embed video in SharePoint

Sometimes we require adding video content to our SharePoint site. There is a very simple way to achieve this functionality.

All we need is Content editor web part to be placed on the page. Source of video file can be from same web application or it can be external source as well or video sitting on some shared drive of your network which everybody has an access.

Go ahead and add content editor web part.

Add following line of code.

<Embed
src="{URL of video / Shared Path pointing to video file}"
width=350
height=350
align=center
autostart=false
loop=false
quality=high
allowFullScreen=true>
</Embed>