I’ve a dropdown area on a sheet (consisting of Wheat, Wooden, Stone, and many others.). When that dropdown area is edited, I would like it to run one of some related features, based mostly on the dropdown choice (when dropdown choice is Wheat, choose from vary X, for instance). I’ve a operate that appears to precisely be logging what cell the dropdown is in, the earlier worth, and the up to date worth. However now that I’ve an if else assertion for every of the choices, it appears to present conflicting values within the log.
I believe both I’m not setting the worth as a string correctly, or I’m instantiating the variables improperly in order that they’re one factor for components of the strategy – and one thing else for various components? Right here is the code beneath, because it present is
operate onEdit (evt) {
var choice = evt.worth;
var vary = evt.vary;
Logger.log("Hex Modified from: " + evt.oldValue + " to : " + choice);
if (choice = "Brick") {
Logger.log("It was " + choice);
Logger.log("The Paste Space is from row " +[range.getRow()+2] + " and column " +[range.getColumn()-1] + " to row " + [range.getRow()+6] + " and column " + [range.getColumn()+1]);
} else if (choice = "Gold") {
Logger.log("It was " + choice);
Logger.log("The Paste Space is from row " +[range.getRow()+2] + " and column " +[range.getColumn()-1] + " to row " + [range.getRow()+6] + " and column " + [range.getColumn()+1]);
} else if (choice = "Sheep") {
Logger.log("It was " + choice);
Logger.log("The Paste Space is from row " +[range.getRow()+2] + " and column " +[range.getColumn()-1] + " to row " + [range.getRow()+6] + " and column " + [range.getColumn()+1]);
} else if (choice = "Stone") {
Logger.log("It was " + choice);
Logger.log("The Paste Space is from row " +[range.getRow()+2] + " and column " +[range.getColumn()-1] + " to row " + [range.getRow()+6] + " and column " + [range.getColumn()+1]);
} else if (choice = "Wheat") {
Logger.log("It was " + choice);
Logger.log("The Paste Space is from row " +[range.getRow()+2] + " and column " +[range.getColumn()-1] + " to row " + [range.getRow()+6] + " and column " + [range.getColumn()+1]);
} else if (choice = "Wooden") {
Logger.log("It was " + choice);
Logger.log("The Paste Space is from row " +[range.getRow()+2] + " and column " +[range.getColumn()-1] + " to row " + [range.getRow()+6] + " and column " + [range.getColumn()+1]);
} else {
Logger.log("One thing went improper");
}
}
The issue is that it appears that evidently when it will get to the if statements, that the ‘choice’ worth is ALWAYS “Brick”, even when the choice within the first a part of the log was appropriately recognized as what the dropdown was edited to be (see screenshot beneath).
So my query is, how can I get the code to run in order that when it appropriately selects what the up to date “choice” variable is (occurring now), it does the right if assertion (not occurring now)?