|
A very simple and quick fix will be to change the = operator, to == operator.
if (window.location.href.toLowerCase == "https: Pages/HomePage.aspx") {
"=" is used to assign the value, and "==" is used to test equality. Also, once converted to lowerCase, there is no sense in having "Page/HomePage" in caps, they will also be in lower format. Anyways, just see if that works otherwise, change them to lower case as well.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
toLowerCase is also a method so you need (). Also, lowercase your text that you are comparing to.
if (window.location.href.toLowerCase() == "https://pages/homepage.aspx") {
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
modified 10-Feb-17 11:05am.
|
|
|
|
|
Except that a lower-case string will never be equal to a string that contains upper-case characters.
Also, the protocol is missing the "//", and the server name is missing.
But apart from that...
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: Except that a lower-case string will never be equal to a string that contains upper-case characters. Ya, I didn't get that far into it. I had read the previous answer and noticed they missed that point. I guess I should have kept on looking.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
exactly
|
|
|
|
|
The location.href will return the full URL, including the server name. The string you're trying to compare it to does not contain the server name, and is missing the "//" from the protocol. Even if you make that string lower-case, it's never going to match the full URL.
Assuming you only want to match the path, use the pathname property instead of the href property:
if (window.location.pathname.toLowerCase() == "/pages/homepage.aspx") {
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I don't know where the crap characters before the full names are coming from...
1211;#Doe Doe, John;#1238;#Doe, John
Can someone show the code on how to clean or ltrim then separate each full name with semi-colon
This is part of the code to show the names where "employee" = full name.
Var employee = "";
if (ListName == "Award - Unit")
{
employee = rows[i].getAttribute('Nominee');
};
str+='<tr><td class=leftcol valign=top><font size="+2">Employee</font></td><td class=rightcol><font size="+2">' + employee + '</font></td></tr>';
|
|
|
|
|
|
is the data coming from sharepoint?
|
|
|
|
|
I'm thinking of using the browser BSON parser with a custom OWIN middleware that will pass queries directly to a Mongo instance for searches, and to WebAPI for processing.
Does anyone have any experience using this as a data transmission system? Primarily I'm curious as to any serious pitfalls that I might be overlooking, particularly with the browser BSON parser.
Edit: This guy GitHub - mongodb/js-bson: BSON Parser for node and browser
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
I'm trying to auto populate the value of a retirement date field by using a DOB (date of birth) value and adding 66 years onto this value.
but it's not working at the moment.
it's just returning the same value as the DOB (so not adding 66 on to it).
here's a fiddle
$( function doDates() {
$("#dateStart").datepicker({
minDate: '-55Y',
changeMonth: true,
changeYear: true,
maxDate: '+3M',
dateFormat: "dd/mm/yy",
onSelect: function (dateStr) {
var min = $(this).datepicker('getDate');
$("#dateEnd").datepicker('option', 'minDate', min || '0');
}
});
$("#dob").datepicker({
minDate: '-55Y',
changeMonth: true,
changeYear: true,
maxDate: '+3M',
dateFormat: "dd/mm/yy",
onSelect: function (dateStr) {
var min = $(this).datepicker('getDate');
$("#dob").datepicker('option', 'minDate', min || '0');
var startDob = $("#dob").datepicker("getDate");
var endDob = new Date();
var daysOld = (endDob - startDob) / (1000 * 60 * 60 * 24);
var retDate = startDob + 66;
$("#diffDaysOld").val(daysOld);
var yearsOld = daysOld / 365.25;
$("#age").val(yearsOld);
$("#dateEnd").val(retDate);
}
});
} );
I've tried both:
var retDate = startDob + 66;
and
var retDate = startDob + (66000 * 60 * 60 * 24);
|
|
|
|
|
I don't think you can just add numbers to a Date field. You need to get the year, add 66, and then set it to the new value. Also, 1000 * 60 * 60 * 24 is the formula for 1 day. See JavaScript Date Reference[^].
|
|
|
|
|
For
retDate = startDob + 66; //( 66000 * 60 * 60 * 24);
Substitute
var retDate = new Date(startDob.getFullYear() + 66, startDob.getMonth(), startDob.getDate());
_______________________________________________________________
Ah don't lean on me man, cause you can't afford the ticket
|
|
|
|
|
Yes, that's done the trick thank you.
Only, it would nice if I could format this date to dd/mm/yy.
I've tried:
$('#dateEnd').datepicker({dateFormat: 'dd.mm.yy'});
$('#retDate').datepicker({dateFormat: 'dd.mm.yy'});
and when this box was an actual datepicker calendar box, I could format like so:
dateFormat: "dd/mm/yy",
however, since the value is now coming from this code section:
var retDate = new Date(startDob.getFullYear() + 66, startDob.getMonth(), startDob.getDate()-1);
it results in this format:
Wed Feb 08 2073 00:00:00 GMT+0000 (GMT Standard Time)
if I could just get rid of the time, that would be good.
fiddle:
https:
modified 2-Feb-17 9:47am.
|
|
|
|
|
When submit a form with mandatory field validation with all the related tabs,Depending on Dropdown Select,Deselect Submit button should get Enable and Disable using Javascript,Ajax,Html and css.
|
|
|
|
|
What is your question?
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hy all there,
I have a problem. I found angular translate example on internet and tried to apply on my MVC app. And it doesnt work and I still dont get why. I tried simple app like HelloWorld and it works, but If I just add translate lib like this:
app.controller("about", ["$scope", "$translate", function ($scope, $translate)
... angular stops working
I tried the simle check test and created simple web on my desktop: index.html, app.js. And guess what? It works. So doesnt that mean that there is some problem with MVC? If it is, and dont know where.
modified 1-Feb-17 2:25am.
|
|
|
|
|
Did you setup the script to download?
<script data-require="angular-translate@*" data-semver="2.5.0" src="https://cdn.rawgit.com/angular-translate/bower-angular-translate/2.5.0/angular-translate.js"></script>
Did you inject the module into your app declaration?
angular.module("myApp",['pascalprecht.translate']);
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Hy, yes I did setup and was injected and you know what? Yesterday it wasnt working but today it works. So doesnt it mean that there was problem with files refreshing in visual studio. Do you have any ideas about how to solve this problem, because I actualy wouldnt like to restart my pc everytime I change my file even the change is minor?
By the way, now I have another problem- now there is a problem with another angular file which belongs to diferent partial MVC page. Is there any way in angular to get logs?
So please, can you help me in these two questions now?
|
|
|
|
|
Okay, well the first is a very common problem if you're working with heavy JS front ends, and that's the browser cache. The best way to handle this (IMO) is to open your browser dev tools (normally F12), disable the browser cache, and refresh. This also has the benefit of showing the console and allowing you to inspect HTTP traffic, which is crucial in debugging JS applications.
Most browsers also support Ctl-F5, which will force a refresh from server.
Your second question is a little more free-form, since we need to define where the logs are. If they're system logs (internal to the computer that the browser is running on) then the answer is a flat no. If they're accessible from the server that your application is running on, you can just create a model for a log entry and load that model in your controller, just like you do any other sort of data.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
I am hoping to find some assistance with a script I am trying to build for our gym. I am rookie javascript programmer and have hit a rut. I will try to keep short and descriptive.
I am using an apikey from Wodify(system for our gym) and a ajax javascript query in our squarespace website to pull the workout down. So Wodify has workout, I want script in squarespace to grab it and display it. (I have this working).
The issue I am running into is I want the script to look to and see if current time is 7PM or greater. If it is 7PM or greater I want the script to grab tomorrow's dates workout (so 25th today). If the time is less than 7PM then it keeps todays workout. Final piece of logic is, if it is after 7PM but there is not a workout posted, then keep today's workout. What I have works some of the time, but other times during the day is incorrect. For some reason it appears the correct date is being applied in the function. I have attached the code below.
I apologize if this is a wall of garbage I really am terrible with javascript.
function loadFormattedWOD(selector, apiKey, date, location, program) {
$.ajax({
url: 'https://app.wodify.com/API/WODs_v1.aspx',
data: {
apiKey: apiKey,
date: date,
location: location,
program: program,
type: "json"
},
dataType: "json",
success: function(data){
try {
if(data && data.RecordList.APIWod.FormattedWOD) {
$(selector).html(data.RecordList.APIWod.FormattedWOD);
return "worked";
}
} catch(err) {
return null;
}
}
});
}
function loadFormattedWOD(selector, apiKey, date, location, program, callback) {
$.ajax({
url: 'https://app.wodify.com/API/WODs_v1.aspx',
data: {
apiKey: apiKey,
date: date,
location: location,
program: program,
callback: callback,
type: "json"
},
dataType: "json",
success: function(data){
try {
if (data && data.RecordList.APIWod.FormattedWOD) {
$(selector).html(data.RecordList.APIWod.FormattedWOD);
console.log('worked');
}
} catch(err) {
if (callback) callback();
}
}
});
}
today = new Date()
if (today.getHours() >=19) {today.setDate(today.getDate()+1);}
else {today.setDate(today.getDate()+0);}
var dateString = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
if(loadFormattedWOD("#wodbody", "myapikey", dateString, "MYGYM", "CrossFit") == null) {
retryWithToday();
}
function retryWithToday() {
today.setDate(today.getDate() - 1);
var dateString = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
loadFormattedWOD("#wodbody", "myapikey", dateString, "MYGYM", "CrossFit");
}
loadFormattedWOD("#wodbody", "myapikey", dateString, "MYGYM", "CrossFit");
|
|
|
|
|
There are a few issues with your code as it is, look at my comments below
today = new Date();
if (today.getHours() >= 19) { today.setDate(today.getDate() + 1); }
else { today.setDate(today.getDate() + 0); }
var dateString = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
if (loadFormattedWOD("#wodbody", "myapikey", dateString, "MYGYM", "CrossFit") == null) {
retryWithToday();
}
function retryWithToday() {
today.setDate(today.getDate() - 1);
var dateString = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
loadFormattedWOD("#wodbody", "myapikey", dateString, "MYGYM", "CrossFit");
}
loadFormattedWOD("#wodbody", "myapikey", dateString, "MYGYM", "CrossFit");
I've re-arranged your code a little, I don't have a valid api key so I can't check the code works etc but this is more the direction you should be heading
function loadFormattedWOD(selector, apiKey, date, location, program, callback) {
$.ajax({
url: 'https://app.wodify.com/API/WODs_v1.aspx',
data: {
apiKey: apiKey,
date: date,
location: location,
program: program,
type: "json"
},
dataType: "json",
success: function (data) {
try {
if (data && data.RecordList.APIWod.FormattedWOD) {
$(selector).html(data.RecordList.APIWod.FormattedWOD);
console.log('worked');
}
else {
if (callback) callback();
}
} catch (err) {
if (callback) callback();
}
}
});
}
function retry() {
console.log('In retry');
var today = new Date();
if (today.getHours() >= 19) {
var dateString = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
loadFormattedWOD("#wodbody", "myapikey", dateString, "MYGYM", "CrossFit", function () {
console.log("failed again");
})
}
else {
console.log("didn't retry");
}
}
today = new Date();
if (today.getHours() >= 19) { today.setDate(today.getDate() + 1); }
var dateString = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
loadFormattedWOD("#wodbody", "myapikey", dateString, "MYGYM", "CrossFit", retry)
|
|
|
|
|
Wow, it appears to be working now! Thank you so much for helping me figure
it out. Hopefully didn't take to much of your time (probably easy for
you). I am still trying to learn all the syntax and how javascript
compiles so this is great. Hope you enjoy the rest of your day.
Again, I really appreciate your help!
Jason
|
|
|
|
|
I added a div to the top of the page like
<div id="wodbody"></div>
and tried it with your API key and it all worked fine for me. To simulate a fail for the first call I changed the api key details but kept the correct details in the "retry" method and it worked there as well. You'll need to step through the code and\or add extra console.log statements to debug what it going on to see exactly where it isn't working.
|
|
|
|
|
Excuse my ignorance, but one final question now that the code completed and working. I've started online classes and have been looking online with no luck. Is it as simple as adding CSS code to format how this information gets displayed on my webpage?
Jason
|
|
|
|
|