Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Mark field as no input required when hidden & dates

  Asked By: Matthew    Date: Oct 19    Category: Sharepoint    Views: 2552

Hi guys,

created a list, i've managed to get field to hide and dates to populate into the applicable fields, I just have 2 queries taht I need some help with

>I need to work out how to get var tmoz to ignore saturdays and sundays - i.e. if request is raised on fri - it would default to the following mondays

>I need to work out how to mark a field as no input required if it is hidden, and input required if visible (urgent change justifacation)

Below is the current java i'm using

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("hideFieldsOnStart");
function hideFieldsOnStart()
{
//hide the control at start
var control = getTagFromIdentifierAndTitle("input","TextField","Urgent Change Justifacation");
var control2 = getTagFromIdentifierAndTitle("input","DateTimeFieldDate","Proposed Implementation Date");
control.parentNode.parentNode.parentNode.style.display="none";
//add an onchange event to the dropdown
getTagFromIdentifierAndTitle("select","DropDownChoice","Change Type").onchange = function() {ChangeEvent()};
//set proposed date to default to tommorow
var Tmoz=new Date(); //get the current date
Tmoz.setDate(Tmoz.getDate()+1);//this adds days
var dd2 = Tmoz.getDate();
var mm2 = Tmoz.getMonth()+1;//January is 0!
var yyyy2 = Tmoz.getFullYear();
if(dd2<10){dd2='0'+dd2}
if(mm2<10){mm2='0'+mm2}
control2.value = dd2+'/'+mm2+'/'+yyyy2
}

function ChangeEvent()
{
var dropDown = getTagFromIdentifierAndTitle("select","DropDownChoice","Change Type");
var option = dropDown.options[dropDown.selectedIndex].text;
var control = getTagFromIdentifierAndTitle("input","TextField","Urgent Change Justifacation");
var control2 = getTagFromIdentifierAndTitle("input","DateTimeFieldDate","Proposed Implementation Date");
//get todays date
var Tday=new Date(); //get the current date
var dd = Tday.getDate();
var mm = Tday.getMonth()+1;//January is 0!
var yyyy = Tday.getFullYear();
if(dd<10){dd='0'+dd}
if(mm<10){mm='0'+mm}
//get tommorows date
var Tmoz=new Date(); //get the current date
Tmoz.setDate(Tmoz.getDate()+1);//this adds days
var dd2 = Tmoz.getDate();
var mm2 = Tmoz.getMonth()+1;//January is 0!
var yyyy2 = Tmoz.getFullYear();
if(dd2<10){dd2='0'+dd2}
if(mm2<10){mm2='0'+mm2}


if(option == "Urgent")
{
control.parentNode.parentNode.parentNode.style.display="";
control2.value = dd+'/'+mm+'/'+yyyy
}
else
{
control.parentNode.parentNode.parentNode.style.display="none";
control2.value = dd2+'/'+mm2+'/'+yyyy2
}
}

//this gets the field based on title identifier and tagname
function getTagFromIdentifierAndTitle(tagName, identifier, title)
{
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++)
{
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len))
{
return tags[i];
}
}
return null;
}
</script>

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Vladi Gubler     Answered On: Oct 26

Use this product: infowisesolutions.com/product.aspx and save yourself the headache. It's free

 
Didn't find what you were looking for? Find more on Mark field as no input required when hidden & dates Or get search suggestion and latest updates.




Tagged: