Tuesday, February 2, 2016

Hide/Show fields in NewForm, EditForm and DispForm.aspx in SharePoint 2010 using JQuery

Custom SharePoint list has Field "Status" with the options
1) Deferred
2) Completed
3) Waiting on response from

and another field is "Waiting on response from" is single line of text



NewForm.aspx :

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" type="text/javascript">
  </script><script type="text/javascript">
$(document).ready(function() {

var loadtext=$("select[title$='Status'] :selected").text();
if(loadtext=='Deferred')
{
$("td.ms-formlabel:contains('Waiting on response from')").parent().hide();
//$("input[title$='Waiting on response from']").attr('disabled', true);
}

$("select[title$='Status']").change(function()
{
var text = $("select[title$='Status'] :selected").text();

if(text!='Waiting on response from')
{

//$("input[title$='Waiting on response from']").attr('disabled', true);
$("td.ms-formlabel:contains('Waiting on response from')").parent().hide();
}
else
{

$("td.ms-formlabel:contains('Waiting on response from')").parent().show();
}
});
}); </script>]

EditForm.aspx:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" type="text/javascript">
  </script><script type="text/javascript">

$(document).ready(function() {

var loadtext=$("select[title$='Status'] :selected").text();
if(loadtext!='Waiting on response from')
{
$("td.ms-formlabel:contains('Waiting on response from')").parent().hide();
}
else
{
$("td.ms-formlabel:contains('Waiting on response from')").parent().show();

}

$("select[title$='Status']").change(function()
{
var text = $("select[title$='Status'] :selected").text();

if(text!='Waiting on response from')
{


$("td.ms-formlabel:contains('Waiting on response from')").parent().hide();
}
else
{

$("td.ms-formlabel:contains('Waiting on response from')").parent().show();
}
});

}); </script>

-------------------------------------------------------------------------------

DispForm.aspx:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" type="text/javascript">

  </script><script type="text/javascript">

$(document).ready(function() {

var text = $('h3:contains("Status")').closest('td').next('td').text();
alert(text.trim());
if(text.trim()!='Waiting on response from')
{
alert(1);
$("td.ms-formlabel:contains('Waiting on response from')").parent().hide();
}
else
{
alert(2);
$("td.ms-formlabel:contains('Waiting on response from')").parent().show();
}



}); </script>

No comments:

Post a Comment