so i've been trying to create an if statement that will prevent the "submitOrder button" from creating the .txt file even when the user hasn't inputted anything within the function "submitOrder"
Everytime I click the button even though there is text it says "please enter a name" also like mentioned it will create a .txt file even though there was no input by the user.
EDIT: Just for clarification guys the text file gets created and saved into the same folder where I have stored the hta file.
function submitOrder(file) {
var fso = new ActiveXObject("scripting.filesystemobject")
var newfile = fso.createTextFile(file, true);
var string = "Thank You For Your Order \r\n";
var orderlist = document.getElementById("orderlist");
var regx = /^[A-Za-z]+$/;
var orderfilename = document.getElementById('orderfilename').value;
for (i = 0; i < orderlist.length; i++) {
if (orderlist.options[i].text != "list of ordered items") {
string = string + orderlist.options[i].text + '\r\n';
}
}
if (orderfilename == "") {
alert("please enter a name for your order")
return false;
}
if (!regx.test("orderfilename")) {
alert("must contain text only")
return false;
} else {
alert(string)
return true;
}
newfile.WriteLine(string);
newfile.Close();
}
<body onload="screen();">
<h1>Gigantuano Pizza Company</h1>
<p>Place your order now!</p>
<select id="pizza">
<option value="0.00">Select a pizza</option>
<option value="10.00">Hawaiian - Large Stuffed Crust - $10.00</option>
<option value="8.00">Hawaiian - XL Standard Base - $8.00</option>
<option value="13.50">Hawaiian - XL Stuffed Crust - $13.50</option>
<option value="10.00">Beef and Onion - Large Stuffed Crust - $10.00</option>
<option value="8.00">Beef and Onion - XL Standard Base - $8.00</option>
<option value="13.50">Beef and Onion - XL Stuffed Crust - $13.50</option>
<option value="11.00">Peperoni Lovers - Large Stuffed Crust - $11.00
</option>
<option value="13.50">Chicken Supreme - Large Stuffed Crust - $13.50
</option>
</select>
<input type="button" onclick="addOrderItem()" value="Add Order Item"><br>
<br> Ordered Items: click to check order
<select id="orderlist">
<option value="0.00">list of ordered items</option>
</select>
<input type="button" onclick="removeOrderItem();" value="Remove Order
Item">
<br> Order Total: <input type="text" id="ordertotal" value=0.0></input><br>
<br>
<br> Type your order submission file name (one word):<input type="text" id="orderfilename" value=""></input>
Click to submit your order:
<input type="button" onclick="submitOrder(document.getElementById('orderfilename').value +
'.txt');" value="Submit Order">
<input type="button" value="Open Order Text File" onclick="OpenFile(
document.getElementById('orderfilename').value + '.txt' );" />
<br>
</body>