Need Help with a Conditional when Clicking a Button
Hello Everyone,
Can anyone Help me with an issue I am having?

When I select a Radio Button and Click OK my script works as intended, but if I forget to select a Radio Button and Click OK I need it to Alert me to "Choose a Product Type". For Var Folder1 I tried to have an if statement that said
IF(choice2 = undefined) {
alert("Choose Product Type");
}
Any suggestions would be appreciated!
var doc = app.activeDocument;
var prefs = load_prefs() // try to loads saved prefs
|| {a:true, b:false, c:false, d:false, e:false, choice:"MN"} // or set default prefs
var choice;
var choice2;
var w = new Window ("dialog", "Production Art Save Options");
var textShow;
var mySelection = w.add("statictext");
mySelection.text = "Please Verify Your Location";
var g = w.add("group");
var a = g.add("radiobutton", undefined, "MN");
var b = g.add("radiobutton", undefined, "WA");
var c = g.add("radiobutton", undefined, "CA");
var d = g.add("radiobutton", undefined, "TX");
var e = g.add("radiobutton", undefined, "Remote");
// Product Type
var mySelection1 = w.add("statictext");
mySelection1.text = "Please Select Your Product Type";
var g2 = w.add("group");
var a2 = g2.add("radiobutton", undefined, "Tooled");
var b2 = g2.add("radiobutton", undefined, "Cast");
var c2 = g2.add("radiobutton", undefined, "Etched");
var d2 = g2.add("radiobutton", undefined, "UV");
////////////////////////////////////////////////////////////////////////
// set the radiobutton from the prefs
a.value = prefs.a;
b.value = prefs.b;
c.value = prefs.c;
d.value = prefs.d;
e.value = prefs.e;
choice = prefs.choice; // <-- updated
var radiobuttons = [a, b, c, d, e];
for (var i = 0; i < radiobuttons.length; i++) {
(function (i) {
radiobuttons[i].onClick = function () {
choice = radiobuttons[i].text;
};
})(i);
}
var radiobuttons2 = [a2, b2, c2, d2];
for (var x = 0; x < radiobuttons2.length; x++) {
(function (x) {
radiobuttons2[x].onClick = function () {
choice2 = radiobuttons2[x].text;
};
})(x);
}
//////////////////////////////////////////////////////////////////////////
var g3 = w.add("group");
var okay = g3.add ("button", undefined, "OK"); //Type of button
okay.onClick = function (){
var sc = "/";
var folderPrefix;
if (choice == "MN") {
folderPrefix = ""M:" + sc + "layout" + sc + "layout" + sc;
} else if (choice == "WA") {
folderPrefix = "W:" + sc + "Art Layouts" + sc;
} else if (choice == "CA") {
folderPrefix = "D:" + sc + "Public" + sc + "layouts" + sc;
} else if (choice == "TX") {
folderPrefix = "T:" + sc + "Graphics" + sc + "Layouts" + sc;
} else if (choice == "Remote") {
folderPrefix = "C:" + sc + "Layout" + sc;
}
var folder1;
if (choice2 = undefined) {
alert("Please Choose a Product Type");
} else if (choice2 == "Tooled") {
// Precision Tooled
folder1 = "Precision Tooled" + sc;
} else if (choice2 == "Cast") {
// Cast
folder1 = "Cast" + sc;
} else if (choice2 == "Etched") {
// Etched
folder1 = "Etch" + sc;
} else if (choice2 == "UV") {
// UV Printed
folder1 = "Giclee-Wayfinding" + sc;
} else if (choice2 == "Ceramic") {
// Ceramic Insert
folder1 = "Ceramic_Insert" + sc;
} else if (choice2 == "Bas Relief") {
// Bas Relief
folder1 = "Bas Relief" + sc;
}
//alert (folder1);
var strEnter = doc.name; //alert(strEnter);
var soNum = strEnter.slice(0,7);
var strEnter = (soNum); //alert(strEnter);
var folderString = (folderPrefix + folder1); //alert(folderString);
var saveString = (folderString + strEnter + ".ai")
var saveString2 = (folderString + strEnter + ".eps");
var newFile = new File (saveString); //alert(newFile);
var newFile2 = new File (saveString2); //alert(newFile2);
//Create the folder structure if it does not exist
activeFolder = new Folder(folderString);
if (activeFolder.exists === false) {
activeFolder.create();
}
if (choice2 === "Cast"){
var NamePreset = 'Illustrator 3';
var saveOpts = new IllustratorSaveOptions()
saveOpts.viewAfterSaving === false
//Checking for overwrite
if (newFile.exists === true) {
if (confirm("Replace existing File?")) {
doc.saveAs(newFile, saveOpts);
doc.close;
}
} else {
newFile = new File (saveString);
doc.saveAs(newFile, saveOpts);
doc.close;
}
}else if (choice2 !== "Cast"){
var NamePreset = 'Illustrator 2020 EPS';
var saveOpts = new EPSSaveOptions();
saveOpts.viewAfterSaving === false
//Checking for overwrite
if (newFile2.exists === true) {
if (confirm("Replace existing File?")) {
doc.saveAs(newFile2, saveOpts);
doc.close;
}
} else {
newFile2 = new File (saveString2);
doc.saveAs(newFile2, saveOpts);
doc.close;
}
}
w.close();}
var cancel = g3.add ("button", undefined, "Cancel"); //Type of button
cancel.onClick = function (){
alert("You've Cancelled This Operation")
w.close();}
var myMessage = w.add("statictext");
myMessage.text = "Every Choice You Make Has An End Result Zig Ziglar";
w.show ();