Valdation on Multi text box


Hi, I would like to do some validation on the below group of text boxes. basically “onBlur” I would like to validate all 4 boxes so that they do not contain the same response. So if 1 has “Citi” and if the user enters “Citi” in place 2, 3 or 4 then an alert is given and the lowest response deleted. Can this be done? May be via custom JavaScript? Screen shot provided.




Jacob H (Moderator) answered

    Hey Scott,

    What an interesting case. I have put together a script for you that should work.

    As you may notice, my script may be longer than what you find by SG Development Team, recently I have taken a simplistic view at programming in Vanilla JS rather than jQuery. It is more of a personal preference.

    In order to implement this you will need to:

    1. Access the Textbox List Question and add the following CSS Class Name “validationDuplicate”.
    2. Add a JavaScript Action on the same page with the following code:

    function addClick() {
    var inputFields = document.querySelectorAll(“.validationDuplicate input[type=text]”);
    var fieldsAmount = inputFields.length;
    for(var i = 0; i < fieldsAmount; i++) {
    inputFields[i].addEventListener(“change”, function(event){
    checkValues(inputFields, fieldsAmount, event);

    function checkValues(inputFields, fieldsAmount, event) {
    for(var a = 0; a < fieldsAmount; a++) {
    var cField = inputFields[a];
    var aField =;
    aField.value = ((cField !== aField) && (cField.value === aField.value)) ? “” : aField.value;

    document.addEventListener(“DOMContentLoaded”, addClick);

    You can test it out on the following survey:

    Please remember:

    1. This script will only remove the duplicate value from inside the textbox
    2. If you want to inform the user with some type of alert, you will need to add to the script
    3. It looks at specific values, so Jacob and Jacob match, where as Jacob and jacob don’t. You would need more validation in the script to make it work.

    Let me know how it all works out for you!

    Jacob H (Moderator) edited answer


      Question stats

      • Active
      • Views2853 times
      • Answers1 answer
      • Followers0 followers