How to disable dates before current date in jsdatepicker - javascript

I am using jsdatepicker to display calendar.
http://javascriptcalendar.org/javascript-date-picker.php
function initialize()
{
new JsDatePick({
useMode:2,
limitToToday :false,
target:"deadlinedate",
dateFormat:"%d-%m-%Y"
});
}
Is there any way to disable all dates before current date.
Any help would be appreciated.
Thanks

download the full version not the min one and change the JsDatePick.prototype.isAvailable function > for < in all 3 ifs

You can add startDate and finishDate parameters to jsDatePick. There is a "limitToToday" control statement in this library (jsDatePick.full.1.x.js) and you can add 2 control statement after this statement, like this:
if (this.oConfiguration.limitToToday){
if ( ! this.isAvailable(this.currentYear, this.currentMonth, parseInt(oDay.getDate()) - 1 ) ){
disabledDayFlag = true;
aDayDiv.setAttribute("isJsDatePickDisabled",1);
}
}
// Your startDate method
if (this.oConfiguration.startDate != ''){
startDate2 = new Date(Date.parse(this.oConfiguration.startDate));
if ( (oDay.getFullYear() < startDate2.getFullYear()) ||
(oDay.getFullYear() == startDate2.getFullYear() && oDay.getMonth() < startDate2.getMonth()) ||
(oDay.getFullYear() == startDate2.getFullYear() && oDay.getMonth() == startDate2.getMonth() && oDay.getDate() < startDate2.getDate() )
)
{
disabledDayFlag = true;
aDayDiv.setAttribute("isJsDatePickDisabled",1);
}
}
// Your finisDate method
if (this.oConfiguration.finishDate != ''){
finishDate2 = new Date(Date.parse(this.oConfiguration.finishDate));
if ( (oDay.getFullYear() > finishDate2.getFullYear()) ||
(oDay.getFullYear() == finishDate2.getFullYear() && oDay.getMonth() > finishDate2.getMonth()) ||
( oDay.getFullYear() == finishDate2.getFullYear() && oDay.getMonth() == finishDate2.getMonth() && oDay.getDate() > finishDate2.getDate() )
)
{
disabledDayFlag = true;
aDayDiv.setAttribute("isJsDatePickDisabled",1);
}
}
You should update "JsDatePick.prototype.setConfiguration" :
JsDatePick.prototype.setConfiguration = function(aConf){
this.oConfiguration.isStripped = (aConf["isStripped"] != null) ? aConf["isStripped"] : false;
this.oConfiguration.useMode = (aConf["useMode"] != null) ? aConf["useMode"] : 1;
this.oConfiguration.selectedDate = (aConf["selectedDate"] != null) ? aConf["selectedDate"] : null;
this.oConfiguration.target = (aConf["target"] != null) ? aConf["target"] : null;
this.oConfiguration.yearsRange = (aConf["yearsRange"] != null) ? aConf["yearsRange"] : [1971,2100];
this.oConfiguration.limitToToday = (aConf["limitToToday"] != null) ? aConf["limitToToday"] : false;
this.oConfiguration.field = (aConf["field"] != null) ? aConf["field"] : false;
this.oConfiguration.cellColorScheme = (aConf["cellColorScheme"] != null) ? aConf["cellColorScheme"] : "ocean_blue";
this.oConfiguration.dateFormat = (aConf["dateFormat"] != null) ? aConf["dateFormat"] : "%m-%d-%Y";
this.oConfiguration.imgPath = (g_jsDatePickImagePath.length != null) ? g_jsDatePickImagePath : "img/";
this.oConfiguration.weekStartDay = (aConf["weekStartDay"] != null) ? aConf["weekStartDay"] : 1;
**this.oConfiguration.startDate = (aConf["startDate"] != null) ? aConf["startDate"] : '';
this.oConfiguration.finishDate = (aConf["finishDate"] != null) ? aConf["finishDate"] : '';**
....
}
When you create your DatePicker object:
g_globalObject = new JsDatePick({
useMode:1,
isStripped:true,
target:"div_calendar",
startDate:"05.01.2013",
finishDate:"05.31.2013"
});

EDIT:
Read it wrong, you have to set the minimum date for that in your option:
var options = {minDate:'03/18/2011',maxDate:today}
$("#datestart").datepicker(options);

Related

onpropertychange not working in cognos new version

In cognos 10.2, the js script below was working well for hide/show functionalities, but after migrating to cognos 11.0.12, it's not working fine.
I replaced
node.onpropertychange=ShowOrHide; with node.addEventListener("change", function(){ShowOrHide();}); and it only worked when I changed the radio button values, not on running the report.
The js script is as below:
<script type="text/javascript">
try
{
var cntlName;
var eleTarget1 = document.getElementById('DateRadPrompt');
var node_listDB = eleTarget1.getElementsByTagName('input');
var eleTarget11 = document.getElementById('divGreyOut');
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined) {
fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}
var list = fW._oLstChoicestodate;
for (var i = 0; i < node_listDB.length; i++)
{
var node = node_listDB[i];
if (node.getAttribute('type') == 'radio')
{
node.addEventListener("change", function(){ShowOrHide();});
}
}
function ShowOrHide()
{
console.log('welcomeShowOrHide');
var DateRadPrompt = document.getElementById('DateRadPrompt');
var eleSource11 = event.srcElement;
if(eleSource11.checked)
{
if (eleSource11.value == 'most_qtr'|| eleSource11.value == 'most_mon1'|| eleSource11.value == 'most_mon2' || eleSource11.value == 'most_mon3' || eleSource11.value == 'cal_prompt' || eleSource11.value == 'most_fsc_yr' || eleSource11.value == 'most_mon12' || eleSource11.value == 'most_qtr4' || eleSource11.value == 'cal_prompt1')
{
eleTarget11.style.display ='none';
}
else
{
eleTarget11.style.display ='block';
}
}
}
list.remove(1);
list.remove(0);
list.removeAttribute("hasLabel");
for (var i=0; i<=node_listDB.length;1++)
{
var nodeDB = node_listDB[i];
if(nodeDB.options[i].selected == true)
{
null
}
else
{
nodeDB.options[0].selected = true
}
}
if (list.options.length==1)
{
eleTarget1.style.display='none';
}
canSubmitPrompt();
}
catch(e)
{
}
</script>`

Divide two Inputs and multiply 100

I have the two functions match and and total working properly. I want the function total project match to divide the first function over the second function multiply times 100. the last function isn't working!
Here is my code so far :
matchContribution.subscribe(function (newValue) {
if (newValue != undefined && newValue != '') {
matchContribution(formatInt(newValue));
var dataValue = Number(matchContribution().replace(/\,/g, ''));
if (dataValue > 999999999999.99 || dataValue < 0) {
matchContribution('');
}
if (loading == false) {
sendCommand('SAVE');
}
}
});
var totalProjectCost = ko.computed(function () {
var total = 0;
var hasUserInput = false;
if (grantRequest() != '' && grantRequest() != undefined) {
hasUserInput = true;
total = total + Number(String(grantRequest()).replace(/\,/g, ''));
}
if (matchContribution() != '' && matchContribution() != undefined) {
hasUserInput = true;
total = total + Number(String(matchContribution()).replace(/\,/g, ''));
}
if (total == 0) {
if (!hasUserInput)
return '';
else
return formatInt('0');
}
else {
if (loading == false) {
sendCommand('SAVE');
}
return formatInt(total);
}
});
var totalProjectMatch = matchContribution()/totalProjectCost();
if(totalProjectMatch>=0)
totalProjectMatch = Math.floor(totalProjectMatch);
else
totalProjectMatch = Math.ceil(totalProjectMatch);
var totalProjectMatch = ko.computed(function () {
var total = 0;
var hasUserInput = false;
if ((grantRequest() != '' && grantRequest() != undefined) && (matchContribution() != '' && matchContribution() != undefined) && (totalProjectCost() != '' && totalProjectCost() != undefined)) {
hasUserInput = true;
total = Number(String(matchContribution()).replace(/\,/g, '')) / Number(String(totalProjectCost()).replace(/\,/g, ''));
total = total * 100;
}
if (total == 0) {
if (!hasUserInput)
return '';
else
return formatInt('0');
}
else {
if (loading == false) {
sendCommand('SAVE');
}
return formatNumber(total);
}
});
I solved the problem! Thanks a lot! Hope that helps other people.

Conversion tag written in javascript

I am researching the following conversion tag written in javascript.
<script type="text/javascript">
var tag_id = 123456789;
var adnetwork_domain = "https://s.adnetwork.net";
</script>
<script type="text/javascript" src="https://s2.adnetwork.net/js/adnetworkRt.js"></script>
https://s2.adnetwork.net/js/adnetworkRt.js
if ("undefined" == typeof adnetwork_domain) var adnetwork_domain = "https://s.adnetwork.net";
if ("undefined" == typeof adnetworkRt) var adnetworkRt = {
init: function() {
try {
if (-1 != document.cookie.indexOf("adnetworkoptout")) return 0;
"undefined" != typeof tag_id && document.createElement("img").setAttribute("src", adnetwork_domain + "/rt.php?tag_id=" + tag_id)
} catch (a) {
console.log(a)
}
}
};
var adnetwork_user_agent = navigator.userAgent;
!navigator.cookieEnabled || (-1 == adnetwork_user_agent.search(/AppleWebKit/) || -1 == adnetwork_user_agent.search(/Android/) && -1 == adnetwork_user_agent.search(/iPhone/) && -1 == adnetwork_user_agent.search(/iPod/) && -1 == adnetwork_user_agent.search(/iPad/)) || adnetworkRt.init();
In the following part, I cannot understand the reason of making img tag and where the img tag is set.
document.createElement("img").setAttribute("src", adnetwork_domain + "/rt.php?tag_id=" + tag_id)
Could you tell me the answer?

addClass javascript for body-click background

i need to add one class at body when i click on.
i know is : $("body").addClass.("ex4Trigger"); but it doesn't work.
I want that when I click on the body, it does something like that =>
....
i dont know if he as possible with that :
var sasClickUrl = "/link/open";
var sasClickTarget = "_self";
document.write('<style>');
document.write('body {');
document.write('background-image: url("/gallery/background/image.jpg")!important;');
document.write('background-repeat: repeat-y;');
if ('top' == 'top with offset') {
document.write('background-position:center 0px;');
} else {
document.write('background-position:center top;');
}
if ('FFFFFF' != "") document.write('background-color: #FFFFFF;');
document.write('padding: 0px 0 0 0;');
if (0) document.write('background-attachment: inherit;');
if (sasClickUrl != "") document.write('cursor: pointer;');
document.write('}');
if (sasClickUrl != "" && !0) document.write('body > *{cursor: default;}');
document.write('</style>');
if (sasClickUrl != "") {
function OpenWin(page) {
if (sasClickTarget == "_parent") window.open(page);
else document.location = page;
}
sasBackClick2213491 = function (e) {
var bglink = sasClickUrl;
EE = e ? e : event;
if (!EE) return;
var tg = EE.target ? EE.target : EE.srcElement;
if ((!tg || tg.tagName != "BODY") && tg.parentNode.tagName != "BODY") return;
var BackLink = OpenWin("" + bglink);
};
document.onclick = sasBackClick2213491;
}
document.write('\r\n');
document.write('\r\n');
thx for help
(PS Sorry for my bad english)
$('body').click('function'){ $(this).addClass('ex4trigger'); }

Internet Explorer may run slowly: change of logic to be done

TableHandler.prototype.IsAlreadySelected = function(dataToCheck)
{
var _this = this;
if (_this.NewTemplateUsageSelected.length > 0)
{
var len = _this.NewTemplateUsageSelected.length;
for (var i = 0; i < len; i++)
{
var an = _this.NewTemplateUsageSelected[i];
var isTemplateUsageDataDuplicate=false;
var isNonApplicableCGDataDuplicate=false;
if ((an.CustomerName == dataToCheck.CustomerName) &&
(an.ProgramName == dataToCheck.ProgramName) &&
(an.WorkpackageName == dataToCheck.WorkpackageName) &&
(an.ActivityName == dataToCheck.ActivityName) &&
(an.SelectedWorkFlowType == dataToCheck.SelectedWorkFlowType) &&
(an.SelectedWorkFlowCategory == dataToCheck.SelectedWorkFlowCategory) &&
(an.ReWorkflow== dataToCheck.ReWorkflow) &&
(an.AllowCheckGroupSelection == dataToCheck.AllowCheckGroupSelection) &&
(an.InitiatorGroupSelection == dataToCheck.InitiatorGroupSelection) &&
(an.R1GroupSelection == dataToCheck.R1GroupSelection) &&
(an.R2GroupSelection == dataToCheck.R2GroupSelection) &&
(an.R3GroupSelection == dataToCheck.R3GroupSelection) &&
(an.R4GroupSelection == dataToCheck.R4GroupSelection) &&
(an.InitiatorMinReworkEffort == dataToCheck.InitiatorMinReworkEffort) &&
(an.R1MinReworkEffort == dataToCheck.R1MinReworkEffort) &&
(an.R2MinReworkEffort == dataToCheck.R2MinReworkEffort) &&
(an.R3MinReworkEffort == dataToCheck.R3MinReworkEffort) &&
(an.R4MinReworkEffort == dataToCheck.R4MinReworkEffort) &&
(an.AllowFileAttachment == dataToCheck.AllowFileAttachment) &&
(an.QualityReviewer== dataToCheck.QualityReviewer) &&
(an.AllowLiabiltySelection == dataToCheck.AllowLiabiltySelection)&&
(an.SetToInactive == dataToCheck.SetToInactive)&&
(an.NonApplicabilityCheckGroupAllowed == dataToCheck.NonApplicabilityCheckGroupAllowed))
{
istemplateusagedataduplicate=true;
}
var checkgroupslendataToCheck=dataToCheck.NonApplicableCheckGroupList.length;
var nalen=an.NonApplicableCheckGroupList.length;
if(checkgroupslendataToCheck == nalen )
{
for (var i = 0 ;i < checkgroupslendataToCheck ; i++)
{
var naDatatocheck= dataToCheck.NonApplicableCheckGroupList[i];
var naData=an.NonApplicableCheckGroupList[i];
if(
( naDatatocheck.INonApplicability == naData.INonApplicability )&&
( naDatatocheck.R1NonApplicability == naData.R1NonApplicability )&&
( naDatatocheck.R2NonApplicability == naData.R2NonApplicability) &&
( naDatatocheck.R3NonApplicability == naData.R3NonApplicability )&&
( naDatatocheck.R4NonApplicability == naData.R4NonApplicability))
isNonApplicableCGDataDuplicate=true;
else
{
isNonApplicableCGDataDuplicate=false;
break;
}
}
if(isNonApplicableCGDataDuplicate==true && istemplateusagedataduplicate==true)
return true;
}
}
}
};
The above code is causing error Internet may run slowly. When i seached for a solution i got solutions like change of registry and IE version, Move the code to cdebehind,usage of plugin etc.. Which are not feasible in our project. So I have to change the above logic.Any inbuilt function in javascript or jquery which i can use to campare a two nested list.
The inner loop needs to use a different variable as its counter or it will make the outer loop go on infinitely. Currently you are using i for both loops.

Categories