0
<form action="" method="post" name="frm" onsubmit="return check()">
<input type="text" name="val[]" class="bla">
<input type="text" name="val[]" class="bla">
<input type="text" name="val[]" class="bla">
<input type="text" name="val[]" class="bla">
<input type="submit" value="send">
</form>

i want to using javascript validation

   check(){
     // if array elements duplicate return false and show error ?
     }

inputs maybe empty , not required , i found that this javascript function , but I could not adapt.

function checkIfArrayIsUnique(arr) {
var map = {}, i, size;
 for (i = 0, size = arr.length; i < size; i++){
if (map[arr[i]]){
 return false;
  }
   map[arr[i]] = true;
  }
  return true;
}
fate
  • 1
  • 1
    possible duplicate of [Easiest way to find duplicate values in a JavaScript array](http://stackoverflow.com/questions/840781/easiest-way-to-find-duplicate-values-in-a-javascript-array) – Veverke Feb 26 '15 at 14:51
  • 1
    Perhaps for you might also be interested in jQuery's built in "unique" function - which works for arrays of DOM elements only. http://api.jquery.com/jquery.unique/ – Veverke Feb 26 '15 at 14:52
  • i dont know take array values from form , can i use class name ? i guess if send array values to checkIfArrayIsUnique function , working script , but how type arr values ? – fate Feb 26 '15 at 15:01

0 Answers0