You can incorporate this validation feature into any existing form, any number of times. The form elements must be named consistently so the script can work with them.
q1a q1b q1c q1d q2a q2b q2c q2d q2e
To use the validation, call rankem(a,b) where the parameters are the question number and its length. In this case, the form handler calls the function twice:
rankem(1,4); rankem(2,5);
Each call will generate a separate alert if there's anything amiss. The global "badrank" variable is a status flag so the main form handler knows if it's allowed to submit(). Note that this demo doesn't acutally do a submit(); instead it just displays a message.