I have some inputs which names is array in one form:
<input type="text" name="email[]" id="email" />
<input type="text" name="email[]" id="email" />
<input type="text" name="email[]" id="email" />
etc.
when I submit the form I need to check in jQuery if have a duplicated value in this inputs, can help me anyone?
thanks :)
I'd do it like this:
var values = $('input[name="email[]"]').map(function() {
return this.value;
}).toArray();
var hasDups = !values.every(function(v,i) {
return values.indexOf(v) == i;
});
$('form').submit(function(e) {
if (hasDups) e.preventDefault();
});
Also, ids should be unique like people are saying in the comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With