I want to disable specific dates in Magento Connect Order Delivery Date Calendar and tried many ways. But could not be successful. Below is my code. It says "TypeError: $.inArray is not a function" when click on the calendar icon.
disableFunc : function(date)
{
var day_off_array = dayoff.split(",") ;
currentTime = new Date();
var d1=currentTime.getDate();
var m1=currentTime.getMonth();
var y1=currentTime.getFullYear();
m1=m1+1;
var counter = 1;
var disabledDays =
["10-20-2013", "10-21-2013", "11-15-2013", "11-17-2013"];
var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
for (i = 0; i < disabledDays.length; i++) {
if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) {
return [false];
}
}
return [true];
if(y < y1)
{
return true;
}
else if(m1 > m && y==y1)
{
return true;
}
}
and this is the original code.
disableFunc : function(date)
{
var y = calendar.date.getFullYear();
var m = calendar.date.getMonth();
var d = calendar.date.getDate();
var day_off_array = dayoff.split(",") ;
//document.write(day_off_array);
currentTime = new Date();
var d1=currentTime.getDate();
var m1=currentTime.getMonth();
var y1=currentTime.getFullYear();
var counter = 1;
for (var i=0; i<day_off_array.length;i++){
if (day_off_array[i]>=0 && day_off_array[i]!=''){
if (date.getDay()==day_off_array[i]){
if (date.getDate()==currentTime.getDate()){
test_flag=true;
}
return true;
}
}
}
if(y < y1)
{
return true;
}
else if(m1 > m && y==y1)
{
return true;
}
}
Any helps would be appreciated.
It's too late to answer the question, but this may help someone like me!
var disabledDays = ["10-20-2014", "10-21-2014", "11-15-2014", "11-17-2014"];
var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
for (i = 0; i < disabledDays.length; i++) {
var dd = (m+1) + '-' + d + '-' + y;
if(disabledDays.indexOf(dd) != -1) {
return true;
}
}
Related
I wrote a program that works well in Google Chrome, but I just realized that it is having problems in IE. IE states that this is due to a syntax error given by the use of arrow functions since they are not supported in the latest IE. Can anyone tell me how to change my code to be able to run it on IE?
function removeRow(a, ref, plt, pcs, loc, trk, din) {
var pro;
swal("Enter the shipment's tracking information:", {
content: "input",
buttons: {
cancel: true,
roll: {
text: "Don't have it",
value: " ",
},
confirm: {
text: "Submit",
}
}
})
.then((value) => {
pro = value;
//console.log(pro);
if (pro !== null || pro === ' ') {
b = '#' + a;
c = '#H' + a;
var d = new Date();
var n = Math.round(d.getTime() / 1000);
var table = $('#mytable')
.DataTable();
// Remove a row by Id:
table.row(b)
.remove()
.draw();
var url = "delete.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: {
id: a,
track: pro,
dateout: n
},
success: function(data) {
//alert(data); // show response from the php script.
//console.log('Success!');
}
});
swal("Success", "Shipment was entered successfully!", "success");
if (ref == '') {
}
var t = $('#myhistory').DataTable();
t.row(c)
.remove()
.draw();
var reference = ref;
var pallets = plt;
var pieces = pcs;
var location = loc;
var carrier = trk;
var datein = din;
var dateout = n;
var rowid = 'H' + a;
if (datein.length < 12) {
var month = datein.toString().substring(0, 1);
if (month == '01') {
month = 'Jan';
} else if (month == '02') {
month = 'Feb';
} else if (month == '03') {
month = 'Mar';
} else if (month == '04') {
month = 'Apr';
} else if (month == '05') {
month = 'May';
} else if (month == '06') {
month = 'Jun';
} else if (month == '07') {
month = 'Jul';
} else if (month == '08') {
month = 'Aug';
} else if (month == '09') {
month = 'Sep';
} else if (month == '10') {
month = 'Oct';
} else if (month == '11') {
month = 'Nov';
} else if (month == '12') {
month = 'Dec';
}
var day = datein.toString().substring(1, 3);
var year = datein.toString().substring(3, 7);
var hour = datein.toString().substring(7, 9);
var second = datein.toString().substring(9, 11);
} else {
var month = datein.toString()
.substring(0, 2);
if (month == '01') {
month = 'Jan';
} else if (month == '02') {
month = 'Feb';
} else if (month == '03') {
month = 'Mar';
} else if (month == '04') {
month = 'Apr';
} else if (month == '05') {
month = 'May';
} else if (month == '06') {
month = 'Jun';
} else if (month == '07') {
month = 'Jul';
} else if (month == '08') {
month = 'Aug';
} else if (month == '09') {
month = 'Sep';
} else if (month == '10') {
month = 'Oct';
} else if (month == '11') {
month = 'Nov';
} else if (month == '12') {
month = 'Dec';
}
var day = datein.toString().substring(2, 4);
var year = datein.toString().substring(4, 8);
var hour = datein.toString().substring(8, 10);
var second = datein.toString().substring(10, 12);
}
var tout = new Date();
var timeout = tout.toString();
var monthout = tout.toString().substring(4, 7);
var dayout = tout.toString().substring(8, 10);
var yearout = tout.toString().substring(11, 16);
var hourout = tout.toString().substring(16, 18);
var secondout = tout.toString().substring(19, 21);
var dateout = monthout + ', ' + dayout + ' ' + yearout + ' at ' + hourout + ':' + secondout;
var datein = month + ', ' + day + ' ' + year + ' at ' + hour + ':' + second;
t.row.add([
reference,
pallets,
pieces,
location,
carrier,
datein,
dateout,
pro
])
.node()
.id = rowid;
t.draw(false);
}
});
}
I could be missing something, but after a quick skim of your code, only this line appears to use any ES6 syntax:
.then((value) => {
Simply change it to:
.then(function(value) {
If you have much more code and don't want to remove such references by hand, #jonrsharpe's suggestion of a transpiler is a good one.
i have this javascript that displays a clock. Is it also possible that it display realtime an div on special time?
if (today >= 12 && today <= 13.30) {
document.body.className += 'lunchbreak';
} else {
document.body.className += 'nolunchbreak';
}
Used clock javascript:
function timepadding(x5) {
if (typeof x5 !== "string") {
x5 = x5.toString()
}
var x6 = 0;
var x7 = 0;
if (x5 % 60 === 0) {
return x5 + ":00"
}
else {
x6 = x5 % 60;
return x6.toString()
}
}
function gettimezone() {
var d = new Date();
var z = document.getElementById("result");
var utcsinceepoch = Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
var y1 = d.getTime()
z.innerHTML= (utcsinceepoch - d.getTime())/3600000;
}
gettimezone();
function utcoffset(time, offset) {
return time + offset;
}
function displayTime() {
var d = new Date();
var y = document.getElementById("a");
var h = (d.getHours()).toString();
var m = (d.getMinutes()).toString();
var s = (d.getSeconds()).toString();
var h2 = ("0" + h).slice(-2);
var m2 = ("0" + m).slice(-2);
var s2 = ("0" + s).slice(-2);
y.style.fontSize = "100px";
y.innerHTML= h2 + ":" + m2 + ":" + s2;
}
setInterval(displayTime, 1000);
I hope you have ideas :)
https://jsbin.com/xubimewoke/edit?html,js,output
When I run my code, there's an error saying: Cannot set property 'src' of null
The error is in this for loop:
for (i=1; i<=48; i++) {
document.getElementById("hour" + i*6 + "map").src = mapAddresses[i-1];
}//end for
Here is all of the code leading up to that point:
<script>
//Create Canvases and Images
var canvas;
var img;
var index;
for (var i = 1; i <= 40; i++) {
index = 6 * i;
canvas = document.createElement("canvas");
canvas.id = "hour" + index + "canvas";
canvas.width = 1024;
canvas.height = 764;
img = document.createElement("img");
img.id = "hour" + index + "map";
img.src = " ";
canvas.appendChild(img);
document.body.appendChild(canvas);
}//end for
//Time Variables
var currentYear = new Date().getFullYear();
var currentMonth = new Date().getMonth() + 1;
var currentDay = new Date().getDate();
var currentHour = new Date().getHours();
var currentRun;
//Formatting Time Variables for URLs
if (currentMonth < 10) {
currentMonth = "0" + currentMonth;
}//end if
if (currentDay < 10) {
currentDay = "0" + currentDay;
}//end if
//Finding Latest Model Run
if (currentHour >= 0 && currentHour < 6) {
currentRun = "00";
}//end if
if (currentHour >= 6 && currentHour < 12) {
currentRun = "06";
}//end if
if (currentHour >= 12 && currentHour < 18) {
currentRun = "12";
}//end if
if (currentHour >= 18 && currentHour < 24) {
currentRun = "18";
}//end if
var currentRun = currentRun;
//Creating URLs
var mapAddresses = [];
for (i=6; i<=240; i=i+6) {
mapAddressFor = "http://www.tropicaltidbits.com/analysis/models/gfs/" + currentYear + currentMonth + currentDay + currentRun + "/gfs_mslp_pcpn_neus_" + i/6 + ".png";
mapAddresses.push(mapAddressFor);
}//end for
//Insert Images to Document
for (i=1; i<=48; i++) {
document.getElementById("hour" + i*6 + "map").src = mapAddresses[i-1];
}//end for
How can I get rid of this error? I can't figure our why there's an error, and how can I fix it?
You create 40 elements:
for (var i = 1; i <= 40; i++) {
// ...
img.id = "hour" + index + "map";
// ...
}//end for
and try to set 48
for (i=1; i<=48; i++) {
document.getElementById("hour" + i*6 + "map").src = mapAddresses[i-1];
}//end for
I want to show the actual appointments of the day in my HTML. I would like to implement it with a JavaScript where I get the name of the appointment and the date out of an excel table.
I already wrote something but it doesn't work and not in the way I want it.
Code:
function appointment() {
var event = [];
var temp = [];
event[0] = ["17.12.2015", "test1"];
event[1] = ["11.12.2015", "TestToday"];
var datum = new Date();
var today = today.getDate();
var month = today.getMonth() + 1;
for (i = 0; i < event.length; i++) {
if (event[i]) {
if (event[i][0] == today && event[i][0] == month) {
event[i][0] = temp[i];
}
}
else {
break;
}
}
if (temp.length == 0) {
document.write("Today is nothing to do");
}
else {
var x2 = "Today " + ((temp.length == 1) ? "is following event: " : "are following events: ");
for (i = 0; i < temp.length; i++) {
x2 += ((temp[i] > 0) ? ((temp[i] == (temp.length - 1)) ? " and " : ", ") : " ") + temp[event[1]][3] + "(" + temp[event[i]][2] + ")";
}
document.write(x2 + " appointment");
}
}
Question: How can I make it work? How can I read the appointment toppic and date out of a excel table?
Change your code to
var datum = new Date().setHours(0,0,0,0);
//you don't need today and month
if (event[i]) {
eventDate = new Date(event[i][0].split(".").reverse()).getTime();
if (datum === eventDate) {
temp.push(event[i][1]); //there was a problem here as well
}
}
else {
break;
}
jsFiddle
Issue is in your for loop. To compare today's date should be in dd.mm.yy format as it is in array:
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10)
dd='0'+dd;
if(mm<10)
mm='0'+mm;
var today = dd+'.'+mm+'.'+yyyy;
for (i = 0; i < event.length; i++) {
if (event[i]) {
if (event[i][0] == today) {
temp[i] = event[i][0];
}
}
// Don't break your for loop
}
Working Fiddle
Is there a better way to format a date imputed by a user. I have an input field where when clicked on a calender pops up and you can chose a date but the user also has the option to type in the date. I want the user to be able to type in 1/12 and my javascript to format it to 01/12/2012. Is there an easy way to go about this with out having to do all types of checks? If not what is the best way to go about this?
I've just gave it a try but not sure if it's the proper way but I think it's working (month/day/year).
$('input[name="txt_date"]').on('blur', function(e){
var dt=$(this).val();
if(dt!='')
{
if(dt.indexOf('/'))
{
var da=dt.split('/');
var l=da.length;
if(l <= 3)
{
var date='';
for(i=0;i<l;i++)
{
if(i==0)
{
if(da[i].match(/^\d{1}|d{2}$/) && da[i]>0 && da[i]<=12)
{
var m=da[i].length==1 ? '0'+da[i] : da[i];
date=m;
}
}
if(i==1)
{
if(da[i].match(/^\d{1}|d{2}$/) && da[i]>0 && da[i]<=31)
{
var d=da[i].length==1 ? '0'+da[i] : da[i];
date+='/'+d;
}
}
if(i==2)
{
if(da[i].match(/^\d{4}$/))
{
date+='/'+da[i];
}
else date+='/'+new Date().getFullYear();
}
}
if(l<3)
{
date+='/'+new Date().getFullYear();
}
if(date.match(/^\d{2}\/\d{2}\/\d{4}$/))
{
$(this).val(date);
}
else alert('invalid date!');
}
}
}
});
DEMO.
This library could help you: http://www.datejs.com/
dd/mm/yyyy is a valid format e.g. in Spain, UK, ...
Here's what I came up with.
var checkDate = function(dateVal, input){
if(dateVal.length == 10){
return;
}
var d = new Date();
var currentMonth = d.getMonth();
var year = d.getFullYear();
var firstIndex = dateVal.indexOf('/');
var month = parseInt(dateVal.substr(0, firstIndex));
var day = parseInt(dateVal.substr(firstIndex + 1, 2));
if(month < 10){
month = '0' + month;
}
if(day < 10){
day = '0' + day;
}
if(month > currentMonth){
year = year - 1;
}
dateVal = month + '/' + day + '/' + year;
if(isNaN(month)){
input.val('');
return;
}
input.val(dateVal);
};