Javascript - Populate country code drop down onChange of country dropdown [closed] - html

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Is there any Javascript plugin to populate country codes on change of country dropdown?

Plug-ins, not that I know of... I know answers shouldn't only include external links, but I guess this might be exception, I will include a few links in case 1 breaks one day...
Since Country names and codes don't change too often nowadays might be safe with this text extract:
http://www.textfixer.com/resources/dropdowns/country-list-iso-codes.txt
then using split(':') function, easy populate text & value of select lists
options elements like this:
function populateCountriesDropDown() {
var file = "countries.txt";
var selectList = document.getElementById('selectID');
var rawlist;
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status == 0) {
rawlist = rawFile.responseText.split('\n');
}
}
}
rawFile.send(null);
for (var i = 0; i < rawlist.length; i++) {
var country = rawlist[i].split(':');
selectList.options[selectList.options.length] = new Option(country[1], country[0]);
}
}
OR other links with what you might be looking for:
http://www.freeformatter.com/iso-country-list-html-select.html
https://github.com/umpirsky/country-list

Related

Check if a string contains a value from an array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
What I'm trying to do is conditionally display a div based on user input. I'd like to parse through the input and if it contains somewhere within it (The input could be a whole paragraph) one of several keywords that are in an array, then it will return true and display the div. This is what I have so far:
jQuery(function($) {
$(".conditional-content-container").hide());
var user_input = $(":input[name=input_4]");
user_input.change(function() {
if (user_input.val().indexOf(["hello", "world", "foo"]) !== -1) {
$(".conditional-content-container").show();
} else {
$(".conditional-content-container").hide();
}
});
});
<div class="conditional-content-container">
Content to be displayed if user input contains the words "hello" or "world" or "foo" somewhere within it
</div>
You need to loop over the array and check if they exist in the string
var words = ['apple', 'foo', 'bar']
function hasAnyWords(str) {
return words.some(word => str.indexOf(word) > -1);
// return words.some(function(word){
// return str.indexOf(word) > -1;
//});
}
function hasAllWords(str) {
return words.every(word => str.indexOf(word) > -1);
// return words.every(function(word){
// return str.indexOf(word) > -1;
//});
}
console.log(hasAnyWords('I like an apple'));
console.log(hasAnyWords('I like a pear'));
console.log(hasAllWords('I like an apple'));
console.log(hasAllWords('I like a bar foo apple'));

Why is the result of (a+b+c')(a'b'+c) not 1? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
So I got his problem as homework in my course, when I solved it the result I came up with was 1, but everywhere I check the solution stops at line 4 is if it is the final solution, but I can't spot the error in my logic for some reason!
Line1: (a+b+c')(a'b'+c)
Line2: =aa'b'+ba'b'+c'a'b'+ac+bc+c'c
Line3: =0+0+c'a'b'+ac+bc+0
Line4: =c'a'b'+ac+bc
Line5: =c'a'b'+c(a+b)
Line6: =c'+c(a'b'+(a+b))
Line7: =1*(a'b'+(a+b))
Line8: =1
You can do a very little bit better if XOR (^) is a primitive operation in your system:
Line1: (a+b+c')(a'b'+c)
Line2: = aa'b'+ba'b'+c'a'b'+ac+bc+c'c
Line3: = 0+0+c'a'b'+ac+bc+0
Line4: = c'a'b'+ac+bc
Line5: = c'a'b'+c(a+b)
Line6: = c'a'b'+c(a'b')'
Line7: = c^(a'b')
Your error is the following:
Line5: = c'a'b'+c(a+b)
Line6: = c'+c(a'b'+(a+b))
Clearly, lines 5 and 6 do not show equivalent expressions because c=0 satisfies the second regardless of a and b whereas c=0, a=1 does not satisfy the first.

Merge divs with same value from angular [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am trying to make a Calendar of my own
https://stackblitz.com/edit/angular-1kfbod?file=src/app/app.component.css
This is a full example of my component.
How can I merge the week divs that have the same value {{day.weekNumber}} (one div instead of 4 for the example below)?
In your case, you should have separate array for your week numbers.
Typescript
public weekNumbers: number[] = [];
public rowWidth: any = 100 + '%';
ngOnInit() {
...
... // your existing code
...
let weeks = [];
for (let i = 1; i <= this.numberOfDaysCurrentMonth; i++) {
this.daysToDisplayInCurrentMonth[i - 1] = new Date(this.currentYear, this.currentMonth - 1, i).getDay();
const day = {
number: i,
weekDay: new Date(this.currentYear, this.currentMonth - 1, i).getDay(),
name: this.dayNames[this.daysToDisplayInCurrentMonth[i - 1]],
weekNumber: this.getWeekNumber(new Date(this.currentYear, this.currentMonth - 1, i))
};
weeks.push(day.weekNumber);
this.days.push(day);
}
this.weekNumbers = [];
weeks.forEach((ele) => {
if(this.weekNumbers.indexOf(ele) < 0) {
this.weekNumbers.push(ele);
}
});
this.rowWidth = (100/this.weekNumbers.length) + '%';
}
HTML
<div class="row-calendar">
<div class="week-number" [style.width]="rowWidth" *ngFor="let week of weekNumbers">
<label class="number-label"><span>{{week}} </span></label>
</div>
</div>

How to find out colour of placeholder? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I know how to set colour of placeholder, but what if I need to find out what's colour of placeholder on some page? I cannot find this property with Chrome Devtools. ColorZilla doesn't help either.
It seems you can't access the pseudo placeholder attribute's CSS in DevTools. You can only get the text value using getAttribute('placeholder') in JavaScript.
However, it is possible to view the style properties using JavaScript instead of manually finding them in the CSS files. This is not ideal, but I created a general purpose function that allows you to specify the selector (or part of the selector), and the attribute you are looking for, and it will loop through all the stylesheets and log a table to the console.
function getSelectorStyle(selector, attribute) {
var rules = [];
function CSSRule(sheet, selector, value) {
this.sheet = sheet;
this.selector = selector;
this.value = value;
}
var styleSheets = document.styleSheets;
for (var i = 0; i < styleSheets.length; i++) {
var currentSheet = document.styleSheets[i];
if (currentSheet != null) {
var ruleList = currentSheet.cssRules;
if (ruleList != null) {
for (var j = 0; j < ruleList.length; j++) {
var currentRule = ruleList[j];
if (currentRule.selectorText != null) {
if (currentRule.selectorText.indexOf(selector) != -1) {
var sheetLocation = currentSheet.href ? currentSheet.href : "inline-css";
var item = new CSSRule(sheetLocation, currentRule.selectorText, currentRule.style[attribute]);
rules.push(item);
}
}
}
}
}
}
console.table(rules)
}
getSelectorStyle("placeholder", "color");
Update:
In terms of your problem with the colour not matching with the Amazon site, as per the comments below, it appears that the selector .form-control::-webkit-input-placeholder is not applied. The input field isn't contained in form-control. The default placeholder colour is applied instead, which is #A9A9A9 (in Chrome at least), which is what you are seeing.

calculate a boolean flag [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a very basic question related to boolean logic.
I have two boolean flags- flagA and flagB. I need to calculate flagC based on the values of flagA and flagB.
The code/rules are:
if($flagA && $flagB) {
$flagC = true;
} else if (!$flagA || !$flagB) {
$flagC = false;
} else if(!$flagA && !$flagB) {
$flagC = true;
}
These rules match with the XNOR truth table - http://en.wikipedia.org/wiki/XNOR_gate
I want to find out different ways to re-write the above code(if possible) with:
fewer lines of code
better performance (even if it is a minute difference)
using bit shifting?
The languages I am hoping to write this in - php, ruby/ruby on rails.
Any help/pointers will be great!
Thanks!
Don't use these languages much but this might work:
$flagC = ($flagA == $flagB);
From the link posted: http://en.wikipedia.org/wiki/XNOR_gate
two-input version implements logical equality, behaving according to the truth table to the right. A HIGH output (1) results if both of the inputs to the gate are the same. If one but not both inputs are HIGH (1), a LOW output (0) results.
So flagC is true when flagA equals flagB.
if($flagA && $flagB) {
$flagC = true;
} else {
$flagC = false;
}
(Your second rule covers all other cases.)