0

I am creating an Info Path form which has a very basic survey. The user has to select the priority from 1 to 10. For this i am using text boxes at the end of each question and user needs to manually enter the number. Now I want to make sure the values are not repeated. Means, they select 1 for a question, they should not use 1 again for any other question. Is it achievable ?

I am not using drop down boxes.

0

You can do this using JavaScript. Add the below code in PreSaveAction function to check for duplicates:

function check(){

var elements = document.getElementsByTagName("input");
var arr = new Array();

for(var i = 0; i < elements.length; i++)
{
   ids = elements[i].id;
   val = elements[i].value;
   if(val == 'null'){
      val = 0;
   }
   arr.push(val);
}
var sorted_arr = arr.sort(); 
var current = null;
var cnt = 0;
msg = '';
for (var i = 0; i <= sorted_arr.length; i++) {
    if (sorted_arr[i] != current) {
        if (cnt > 1) {
            msg += current + ' occurs --> ' + cnt + ' times\n';
        }
        current = sorted_arr[i];
        cnt = 1;
    } else {
        cnt++;
    }
}

if (msg != '') {
    alert('Please remove duplicates:\n'+msg);
    return false;
} 

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.