TruClient allows you to automatically select a random value from a drop-down list by using 0 as step Ordinal. How to avoid selecting the first value?
TruClient allows you to automatically select a random value from a drop-down list. To do so:
Leave the step 'Text' argument blank.
Use 0 as a step 'Ordinal' argument.
In some cases, there are values that should not be selected, like the "Please select" value in the following example:
<option value="">Please select...</option>
If 0 is used as a step 'Ordinal' argument, TruClient will select any of the 4 values, as they are all valid.
To prevent selecting the first option, the following workaround could be used:
Leave the step 'Text' argument blank
Math.floor(Math.random() * (object.options.length - 1) + 2);
The above code will return a random number between 2 and the total number of elements in the list.