programmatically construct condition for use in if() statement
up vote
6
down vote
favorite
Let's assume for a moment that I have something like this:
if( document.getElementById('div1').innerHTML &&
document.getElementById('div2').innerHTML &&
document.getElementById('div3').innerHTML &&
document.getElementById('div4').innerHTML &&
document.getElementById('div5').innerHTML &&
...
document.getElementById('div100').innerHTML)
Obviously typing out and maintaining a big conditional statement like this is problematic.
What I would like is some solution like:
var conditional = "";
for(var i = 1; i <= 100; i++){
conditional += "document.getElementById('div" + i +"').innerHTML";
if(i < 100) {
conditional += " && ";
}
}
if(interpretStringAsJSExpression(conditional)){
console.log("all my divs have content");
}
Is something like this possible in Javascript?
Edit:
Great answers have been submitted, and I am sure that I and others will benefit from them. However, purely from a place of curiosity, is it possible to store and run Javascript expressions or commands in strings? Like I have proposed in my example: interpretStringAsJSExpression(conditional)
javascript
add a comment |
up vote
6
down vote
favorite
Let's assume for a moment that I have something like this:
if( document.getElementById('div1').innerHTML &&
document.getElementById('div2').innerHTML &&
document.getElementById('div3').innerHTML &&
document.getElementById('div4').innerHTML &&
document.getElementById('div5').innerHTML &&
...
document.getElementById('div100').innerHTML)
Obviously typing out and maintaining a big conditional statement like this is problematic.
What I would like is some solution like:
var conditional = "";
for(var i = 1; i <= 100; i++){
conditional += "document.getElementById('div" + i +"').innerHTML";
if(i < 100) {
conditional += " && ";
}
}
if(interpretStringAsJSExpression(conditional)){
console.log("all my divs have content");
}
Is something like this possible in Javascript?
Edit:
Great answers have been submitted, and I am sure that I and others will benefit from them. However, purely from a place of curiosity, is it possible to store and run Javascript expressions or commands in strings? Like I have proposed in my example: interpretStringAsJSExpression(conditional)
javascript
1
You can execute a string witheval(conditional)
. It's almost always the wrong solution, though.
– Barmar
3 hours ago
add a comment |
up vote
6
down vote
favorite
up vote
6
down vote
favorite
Let's assume for a moment that I have something like this:
if( document.getElementById('div1').innerHTML &&
document.getElementById('div2').innerHTML &&
document.getElementById('div3').innerHTML &&
document.getElementById('div4').innerHTML &&
document.getElementById('div5').innerHTML &&
...
document.getElementById('div100').innerHTML)
Obviously typing out and maintaining a big conditional statement like this is problematic.
What I would like is some solution like:
var conditional = "";
for(var i = 1; i <= 100; i++){
conditional += "document.getElementById('div" + i +"').innerHTML";
if(i < 100) {
conditional += " && ";
}
}
if(interpretStringAsJSExpression(conditional)){
console.log("all my divs have content");
}
Is something like this possible in Javascript?
Edit:
Great answers have been submitted, and I am sure that I and others will benefit from them. However, purely from a place of curiosity, is it possible to store and run Javascript expressions or commands in strings? Like I have proposed in my example: interpretStringAsJSExpression(conditional)
javascript
Let's assume for a moment that I have something like this:
if( document.getElementById('div1').innerHTML &&
document.getElementById('div2').innerHTML &&
document.getElementById('div3').innerHTML &&
document.getElementById('div4').innerHTML &&
document.getElementById('div5').innerHTML &&
...
document.getElementById('div100').innerHTML)
Obviously typing out and maintaining a big conditional statement like this is problematic.
What I would like is some solution like:
var conditional = "";
for(var i = 1; i <= 100; i++){
conditional += "document.getElementById('div" + i +"').innerHTML";
if(i < 100) {
conditional += " && ";
}
}
if(interpretStringAsJSExpression(conditional)){
console.log("all my divs have content");
}
Is something like this possible in Javascript?
Edit:
Great answers have been submitted, and I am sure that I and others will benefit from them. However, purely from a place of curiosity, is it possible to store and run Javascript expressions or commands in strings? Like I have proposed in my example: interpretStringAsJSExpression(conditional)
javascript
javascript
edited 4 hours ago
asked 4 hours ago
WillD
19211
19211
1
You can execute a string witheval(conditional)
. It's almost always the wrong solution, though.
– Barmar
3 hours ago
add a comment |
1
You can execute a string witheval(conditional)
. It's almost always the wrong solution, though.
– Barmar
3 hours ago
1
1
You can execute a string with
eval(conditional)
. It's almost always the wrong solution, though.– Barmar
3 hours ago
You can execute a string with
eval(conditional)
. It's almost always the wrong solution, though.– Barmar
3 hours ago
add a comment |
5 Answers
5
active
oldest
votes
up vote
1
down vote
accepted
As the other answers said, you can solve your conditions problem more easily.
But, to answer your new question
purely from a place of curiosity, is it possible to store and run
Javascript expressions or commands in strings?
Yes, you can write javascript to a string and execute it later with eval. Which you should not do if you are concerned with security or performance.
Since this most closely answers my question I am going to accept it, though I recognize that for the example I gave there are more direct solutions, and furthermore thateval()
has its own problems.
– WillD
2 hours ago
add a comment |
up vote
5
down vote
You can do the tests in a loop.
var allOK = true;
for (var i = 1; i <= 100; i++) {
if (!document.getElementById("div"+i).innerHTML) {
allOK = false;
break;
}
}
if (allOK) {
console.log("all my divs have content");
}
You could also give all your DIVs a common class, then use a built-in iterator.
var allDivs = document.getElementsByClassName("divClass");
if (Array.from(allDivs).every(div => div.innerHTML)) {
console.log("all my divs have content");
}
I suppose document.getElementById("div"+i).innerHTML will return a string not a boolean. isn't it?
– Gaurav
4 hours ago
1
@Gaurav An empty string is falsey.
– Barmar
4 hours ago
+1, slow typing on my part and this is how I would do it. Didn't know about the built in iterator method. very cool!
– billynoah
4 hours ago
add a comment |
up vote
4
down vote
Why interpret a string of code. There are other means like for
loops:
var conditionResult = true;
for(var i = 1; i < 101; i++) {
conditionResult = conditionResult && document.getElementById('div' + i).innerHTML;
}
if(conditionResult) {
// do something here
}
You can also use array methods like some
and every
if you have the elements in an array:
var arr = [/* array of DOM elements */];
var conditionResult = arr.every(elem => elem.innerHTML); // this is equivalent to (innerHTML && innerHTML && ...)
var conditionResult = arr.some(elem => elem.innerHTML); // this is equivalent to (innerHTML || innerHTML || ...)
add a comment |
up vote
2
down vote
Use document.querySelectorAll for this type of operation
// Get all the divs that have ids which start with div
var theDivs = document.querySelectorAll('[id^="div"]');
var i,l,el,divsWithContent = ;
// Loop through all theDivs
l = theDivs.length;
for(i = 0; i < l; i++) {
// el is the div
el = theDivs[i];
// Test to make sure the id is div followed by one or more digits
if (/^divd+$/.test(el.id)) {
// If the div has something in it other than spaces, it's got content
if (el.textContent.trim() !== "") {
// Save the divs with content in the array
divsWithContent.push(el.id);
}
}
}
// Show the results
document.getElementById("result").textContent = divsWithContent.join("n");
<h1>Div test</h1>
<div id="div1">This</div>
<div id="div2">that</div>
<div id="div3"></div>
<div id="div4">and</div>
<div id="div5">the other thing</div>
<h2>Divs with content</h2>
<pre id="result"></pre>
Ref: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
add a comment |
up vote
1
down vote
You can set condition
to true
and check each one, setting condition
to false and break out of the loop if any are false.
var conditional = true;
for(var i = 1; i <= 100; i++){
if (!document.getElementById('div' + i).innerHTML) {
condition = false;
break;
}
}
add a comment |
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
As the other answers said, you can solve your conditions problem more easily.
But, to answer your new question
purely from a place of curiosity, is it possible to store and run
Javascript expressions or commands in strings?
Yes, you can write javascript to a string and execute it later with eval. Which you should not do if you are concerned with security or performance.
Since this most closely answers my question I am going to accept it, though I recognize that for the example I gave there are more direct solutions, and furthermore thateval()
has its own problems.
– WillD
2 hours ago
add a comment |
up vote
1
down vote
accepted
As the other answers said, you can solve your conditions problem more easily.
But, to answer your new question
purely from a place of curiosity, is it possible to store and run
Javascript expressions or commands in strings?
Yes, you can write javascript to a string and execute it later with eval. Which you should not do if you are concerned with security or performance.
Since this most closely answers my question I am going to accept it, though I recognize that for the example I gave there are more direct solutions, and furthermore thateval()
has its own problems.
– WillD
2 hours ago
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
As the other answers said, you can solve your conditions problem more easily.
But, to answer your new question
purely from a place of curiosity, is it possible to store and run
Javascript expressions or commands in strings?
Yes, you can write javascript to a string and execute it later with eval. Which you should not do if you are concerned with security or performance.
As the other answers said, you can solve your conditions problem more easily.
But, to answer your new question
purely from a place of curiosity, is it possible to store and run
Javascript expressions or commands in strings?
Yes, you can write javascript to a string and execute it later with eval. Which you should not do if you are concerned with security or performance.
answered 3 hours ago
jorbuedo
1766
1766
Since this most closely answers my question I am going to accept it, though I recognize that for the example I gave there are more direct solutions, and furthermore thateval()
has its own problems.
– WillD
2 hours ago
add a comment |
Since this most closely answers my question I am going to accept it, though I recognize that for the example I gave there are more direct solutions, and furthermore thateval()
has its own problems.
– WillD
2 hours ago
Since this most closely answers my question I am going to accept it, though I recognize that for the example I gave there are more direct solutions, and furthermore that
eval()
has its own problems.– WillD
2 hours ago
Since this most closely answers my question I am going to accept it, though I recognize that for the example I gave there are more direct solutions, and furthermore that
eval()
has its own problems.– WillD
2 hours ago
add a comment |
up vote
5
down vote
You can do the tests in a loop.
var allOK = true;
for (var i = 1; i <= 100; i++) {
if (!document.getElementById("div"+i).innerHTML) {
allOK = false;
break;
}
}
if (allOK) {
console.log("all my divs have content");
}
You could also give all your DIVs a common class, then use a built-in iterator.
var allDivs = document.getElementsByClassName("divClass");
if (Array.from(allDivs).every(div => div.innerHTML)) {
console.log("all my divs have content");
}
I suppose document.getElementById("div"+i).innerHTML will return a string not a boolean. isn't it?
– Gaurav
4 hours ago
1
@Gaurav An empty string is falsey.
– Barmar
4 hours ago
+1, slow typing on my part and this is how I would do it. Didn't know about the built in iterator method. very cool!
– billynoah
4 hours ago
add a comment |
up vote
5
down vote
You can do the tests in a loop.
var allOK = true;
for (var i = 1; i <= 100; i++) {
if (!document.getElementById("div"+i).innerHTML) {
allOK = false;
break;
}
}
if (allOK) {
console.log("all my divs have content");
}
You could also give all your DIVs a common class, then use a built-in iterator.
var allDivs = document.getElementsByClassName("divClass");
if (Array.from(allDivs).every(div => div.innerHTML)) {
console.log("all my divs have content");
}
I suppose document.getElementById("div"+i).innerHTML will return a string not a boolean. isn't it?
– Gaurav
4 hours ago
1
@Gaurav An empty string is falsey.
– Barmar
4 hours ago
+1, slow typing on my part and this is how I would do it. Didn't know about the built in iterator method. very cool!
– billynoah
4 hours ago
add a comment |
up vote
5
down vote
up vote
5
down vote
You can do the tests in a loop.
var allOK = true;
for (var i = 1; i <= 100; i++) {
if (!document.getElementById("div"+i).innerHTML) {
allOK = false;
break;
}
}
if (allOK) {
console.log("all my divs have content");
}
You could also give all your DIVs a common class, then use a built-in iterator.
var allDivs = document.getElementsByClassName("divClass");
if (Array.from(allDivs).every(div => div.innerHTML)) {
console.log("all my divs have content");
}
You can do the tests in a loop.
var allOK = true;
for (var i = 1; i <= 100; i++) {
if (!document.getElementById("div"+i).innerHTML) {
allOK = false;
break;
}
}
if (allOK) {
console.log("all my divs have content");
}
You could also give all your DIVs a common class, then use a built-in iterator.
var allDivs = document.getElementsByClassName("divClass");
if (Array.from(allDivs).every(div => div.innerHTML)) {
console.log("all my divs have content");
}
edited 4 hours ago
answered 4 hours ago
Barmar
415k34239340
415k34239340
I suppose document.getElementById("div"+i).innerHTML will return a string not a boolean. isn't it?
– Gaurav
4 hours ago
1
@Gaurav An empty string is falsey.
– Barmar
4 hours ago
+1, slow typing on my part and this is how I would do it. Didn't know about the built in iterator method. very cool!
– billynoah
4 hours ago
add a comment |
I suppose document.getElementById("div"+i).innerHTML will return a string not a boolean. isn't it?
– Gaurav
4 hours ago
1
@Gaurav An empty string is falsey.
– Barmar
4 hours ago
+1, slow typing on my part and this is how I would do it. Didn't know about the built in iterator method. very cool!
– billynoah
4 hours ago
I suppose document.getElementById("div"+i).innerHTML will return a string not a boolean. isn't it?
– Gaurav
4 hours ago
I suppose document.getElementById("div"+i).innerHTML will return a string not a boolean. isn't it?
– Gaurav
4 hours ago
1
1
@Gaurav An empty string is falsey.
– Barmar
4 hours ago
@Gaurav An empty string is falsey.
– Barmar
4 hours ago
+1, slow typing on my part and this is how I would do it. Didn't know about the built in iterator method. very cool!
– billynoah
4 hours ago
+1, slow typing on my part and this is how I would do it. Didn't know about the built in iterator method. very cool!
– billynoah
4 hours ago
add a comment |
up vote
4
down vote
Why interpret a string of code. There are other means like for
loops:
var conditionResult = true;
for(var i = 1; i < 101; i++) {
conditionResult = conditionResult && document.getElementById('div' + i).innerHTML;
}
if(conditionResult) {
// do something here
}
You can also use array methods like some
and every
if you have the elements in an array:
var arr = [/* array of DOM elements */];
var conditionResult = arr.every(elem => elem.innerHTML); // this is equivalent to (innerHTML && innerHTML && ...)
var conditionResult = arr.some(elem => elem.innerHTML); // this is equivalent to (innerHTML || innerHTML || ...)
add a comment |
up vote
4
down vote
Why interpret a string of code. There are other means like for
loops:
var conditionResult = true;
for(var i = 1; i < 101; i++) {
conditionResult = conditionResult && document.getElementById('div' + i).innerHTML;
}
if(conditionResult) {
// do something here
}
You can also use array methods like some
and every
if you have the elements in an array:
var arr = [/* array of DOM elements */];
var conditionResult = arr.every(elem => elem.innerHTML); // this is equivalent to (innerHTML && innerHTML && ...)
var conditionResult = arr.some(elem => elem.innerHTML); // this is equivalent to (innerHTML || innerHTML || ...)
add a comment |
up vote
4
down vote
up vote
4
down vote
Why interpret a string of code. There are other means like for
loops:
var conditionResult = true;
for(var i = 1; i < 101; i++) {
conditionResult = conditionResult && document.getElementById('div' + i).innerHTML;
}
if(conditionResult) {
// do something here
}
You can also use array methods like some
and every
if you have the elements in an array:
var arr = [/* array of DOM elements */];
var conditionResult = arr.every(elem => elem.innerHTML); // this is equivalent to (innerHTML && innerHTML && ...)
var conditionResult = arr.some(elem => elem.innerHTML); // this is equivalent to (innerHTML || innerHTML || ...)
Why interpret a string of code. There are other means like for
loops:
var conditionResult = true;
for(var i = 1; i < 101; i++) {
conditionResult = conditionResult && document.getElementById('div' + i).innerHTML;
}
if(conditionResult) {
// do something here
}
You can also use array methods like some
and every
if you have the elements in an array:
var arr = [/* array of DOM elements */];
var conditionResult = arr.every(elem => elem.innerHTML); // this is equivalent to (innerHTML && innerHTML && ...)
var conditionResult = arr.some(elem => elem.innerHTML); // this is equivalent to (innerHTML || innerHTML || ...)
answered 4 hours ago
ibrahim mahrir
21.3k41746
21.3k41746
add a comment |
add a comment |
up vote
2
down vote
Use document.querySelectorAll for this type of operation
// Get all the divs that have ids which start with div
var theDivs = document.querySelectorAll('[id^="div"]');
var i,l,el,divsWithContent = ;
// Loop through all theDivs
l = theDivs.length;
for(i = 0; i < l; i++) {
// el is the div
el = theDivs[i];
// Test to make sure the id is div followed by one or more digits
if (/^divd+$/.test(el.id)) {
// If the div has something in it other than spaces, it's got content
if (el.textContent.trim() !== "") {
// Save the divs with content in the array
divsWithContent.push(el.id);
}
}
}
// Show the results
document.getElementById("result").textContent = divsWithContent.join("n");
<h1>Div test</h1>
<div id="div1">This</div>
<div id="div2">that</div>
<div id="div3"></div>
<div id="div4">and</div>
<div id="div5">the other thing</div>
<h2>Divs with content</h2>
<pre id="result"></pre>
Ref: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
add a comment |
up vote
2
down vote
Use document.querySelectorAll for this type of operation
// Get all the divs that have ids which start with div
var theDivs = document.querySelectorAll('[id^="div"]');
var i,l,el,divsWithContent = ;
// Loop through all theDivs
l = theDivs.length;
for(i = 0; i < l; i++) {
// el is the div
el = theDivs[i];
// Test to make sure the id is div followed by one or more digits
if (/^divd+$/.test(el.id)) {
// If the div has something in it other than spaces, it's got content
if (el.textContent.trim() !== "") {
// Save the divs with content in the array
divsWithContent.push(el.id);
}
}
}
// Show the results
document.getElementById("result").textContent = divsWithContent.join("n");
<h1>Div test</h1>
<div id="div1">This</div>
<div id="div2">that</div>
<div id="div3"></div>
<div id="div4">and</div>
<div id="div5">the other thing</div>
<h2>Divs with content</h2>
<pre id="result"></pre>
Ref: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
add a comment |
up vote
2
down vote
up vote
2
down vote
Use document.querySelectorAll for this type of operation
// Get all the divs that have ids which start with div
var theDivs = document.querySelectorAll('[id^="div"]');
var i,l,el,divsWithContent = ;
// Loop through all theDivs
l = theDivs.length;
for(i = 0; i < l; i++) {
// el is the div
el = theDivs[i];
// Test to make sure the id is div followed by one or more digits
if (/^divd+$/.test(el.id)) {
// If the div has something in it other than spaces, it's got content
if (el.textContent.trim() !== "") {
// Save the divs with content in the array
divsWithContent.push(el.id);
}
}
}
// Show the results
document.getElementById("result").textContent = divsWithContent.join("n");
<h1>Div test</h1>
<div id="div1">This</div>
<div id="div2">that</div>
<div id="div3"></div>
<div id="div4">and</div>
<div id="div5">the other thing</div>
<h2>Divs with content</h2>
<pre id="result"></pre>
Ref: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
Use document.querySelectorAll for this type of operation
// Get all the divs that have ids which start with div
var theDivs = document.querySelectorAll('[id^="div"]');
var i,l,el,divsWithContent = ;
// Loop through all theDivs
l = theDivs.length;
for(i = 0; i < l; i++) {
// el is the div
el = theDivs[i];
// Test to make sure the id is div followed by one or more digits
if (/^divd+$/.test(el.id)) {
// If the div has something in it other than spaces, it's got content
if (el.textContent.trim() !== "") {
// Save the divs with content in the array
divsWithContent.push(el.id);
}
}
}
// Show the results
document.getElementById("result").textContent = divsWithContent.join("n");
<h1>Div test</h1>
<div id="div1">This</div>
<div id="div2">that</div>
<div id="div3"></div>
<div id="div4">and</div>
<div id="div5">the other thing</div>
<h2>Divs with content</h2>
<pre id="result"></pre>
Ref: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
// Get all the divs that have ids which start with div
var theDivs = document.querySelectorAll('[id^="div"]');
var i,l,el,divsWithContent = ;
// Loop through all theDivs
l = theDivs.length;
for(i = 0; i < l; i++) {
// el is the div
el = theDivs[i];
// Test to make sure the id is div followed by one or more digits
if (/^divd+$/.test(el.id)) {
// If the div has something in it other than spaces, it's got content
if (el.textContent.trim() !== "") {
// Save the divs with content in the array
divsWithContent.push(el.id);
}
}
}
// Show the results
document.getElementById("result").textContent = divsWithContent.join("n");
<h1>Div test</h1>
<div id="div1">This</div>
<div id="div2">that</div>
<div id="div3"></div>
<div id="div4">and</div>
<div id="div5">the other thing</div>
<h2>Divs with content</h2>
<pre id="result"></pre>
// Get all the divs that have ids which start with div
var theDivs = document.querySelectorAll('[id^="div"]');
var i,l,el,divsWithContent = ;
// Loop through all theDivs
l = theDivs.length;
for(i = 0; i < l; i++) {
// el is the div
el = theDivs[i];
// Test to make sure the id is div followed by one or more digits
if (/^divd+$/.test(el.id)) {
// If the div has something in it other than spaces, it's got content
if (el.textContent.trim() !== "") {
// Save the divs with content in the array
divsWithContent.push(el.id);
}
}
}
// Show the results
document.getElementById("result").textContent = divsWithContent.join("n");
<h1>Div test</h1>
<div id="div1">This</div>
<div id="div2">that</div>
<div id="div3"></div>
<div id="div4">and</div>
<div id="div5">the other thing</div>
<h2>Divs with content</h2>
<pre id="result"></pre>
answered 3 hours ago
user2182349
7,01311632
7,01311632
add a comment |
add a comment |
up vote
1
down vote
You can set condition
to true
and check each one, setting condition
to false and break out of the loop if any are false.
var conditional = true;
for(var i = 1; i <= 100; i++){
if (!document.getElementById('div' + i).innerHTML) {
condition = false;
break;
}
}
add a comment |
up vote
1
down vote
You can set condition
to true
and check each one, setting condition
to false and break out of the loop if any are false.
var conditional = true;
for(var i = 1; i <= 100; i++){
if (!document.getElementById('div' + i).innerHTML) {
condition = false;
break;
}
}
add a comment |
up vote
1
down vote
up vote
1
down vote
You can set condition
to true
and check each one, setting condition
to false and break out of the loop if any are false.
var conditional = true;
for(var i = 1; i <= 100; i++){
if (!document.getElementById('div' + i).innerHTML) {
condition = false;
break;
}
}
You can set condition
to true
and check each one, setting condition
to false and break out of the loop if any are false.
var conditional = true;
for(var i = 1; i <= 100; i++){
if (!document.getElementById('div' + i).innerHTML) {
condition = false;
break;
}
}
answered 4 hours ago
billynoah
10.2k54261
10.2k54261
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53689001%2fprogrammatically-construct-condition-for-use-in-if-statement%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You can execute a string with
eval(conditional)
. It's almost always the wrong solution, though.– Barmar
3 hours ago