Reputation: 1
I have html href and linked to a function in js file. From the html when user clicked, it will validate user's profile by country. If the user's profile= TH and SG it will open a url, else it will open b url. Please help me. I do not know whats wrong with my code
/* API Completion */
api.done(function (a, c, d) {
console.log(a.d);
var countryCode = "";
function checkCountry(upp) {
return upp.Key === "CountryCode";
}
var arrUPP = a.d.UserProfileProperties.results.filter(checkCountry);
//btn.addEventListener("click", travel);
$(document).ready(function()
{
//$('ul.nav li').click(function()
if (arrUPP.length > 0 && arrUPP[0].Value) {
countryCode = arrUPP[0].Value;
}
else if (countryCode == "TH" && countryCode == "SG") {
window.location.href = 'https://....a url';
} else {
window.location.href = 'https://....b url';
return;
}
});
//}
});
api.fail(function (a, b, c) {
var errorMessage = [];
errorMessage.push(errorMessage);
errorMessage.push("Error: " + a.responseJSON.error.message.value);
alert(errorMessage.join("\n"));
});
<li class="main">
<a class="travel" href="javascript:travel();" target="blank">
<i class="icon-travel"></i>
<span>Country</span>
</a>
</li>
Upvotes: 0
Views: 85
Reputation: 534
This will never be true countryCode == "TH" && countryCode == "SG"
. You expect one value to be both "TH" AND "SG". You probably meant to use ||
.
Upvotes: 0