Getting the idea from this thread, I came up with an alternative product options validation script for the product options (for a site that I've been working on) that will get any select drop-down elements that their id is something llike "po118", "po119", etc (which is how the option drop-downs are named from x-cart) and display an alert message if the customer has any of these select boxes selected at their 1st option (which could be a hard-coded "select size" option, and not a specific size). So, in this way, the customer is prompted to select for every option drop-down, a specific option (other than the 1st one) in order to be able to proceed to checkout. Actually, I
use a regular expression in the getElementById() method. So, someone could even import that script in a massive csv product/variants import and have the same script for each product (which is what I'm planning to do next).
The code below is for a product with 2 option groups. Goes without saying, it could be replicated for any number of options.
Code:
var order_Form = document.orderform;
// declare our regex
var re = new RegExp(/po\d+/);
// loop through the form elements
for(i = 0; i < order_Form.elements.length; i++){
// execute our regular expression against each element id
var m = re.test(order_Form.elements[i].id);
if (m) {
var matched_id1=order_Form.elements[i].id;
var matched_id2=order_Form.elements[i+1].id; // e.g. "po119", i.e. the id of the next option select element
if (document.getElementById(matched_id1).selectedIndex == 0)
{
alert('You must select an optionA for your item.'); return false;
}
if (document.getElementById(matched_id2).selectedIndex == 0)
{
alert('You must select an optionB for your item.'); return false;
}
else return true;
}
}