<form name="f1" id="f1" onsubmit="return checkToSubmit();" method="post">
<input type="text" name="i[]" value="i1" /><br />
<input type="text" name="i[]" value="i2" /><br />
<input type="text" name="i[]" value="i3" /><br />
<input type="text" name="i[]" value="i4" /><br />
<input type="text" name="i[]" value="i5" /><br />
<input type="text" name="i[]" value="i6" /><br />
<input type="submit" value="OK" />
</form>
<script>
function checkToSubmit() {
var valid = true;
var hasData = false;
// storage unique values user entered
var enterList = '';
var inputs = document.f1['i[]'];
var nInput = inputs.length;
var vInput;
for (var i = 0; i < nInput; i++) {
var input = inputs[i];
vInput = inputs[i].value;
vInput = vInput.replace(/[^a-z0-9_-]/gi, '');//normalize data
if (vInput == '') {
continue;
}
hasData = true;
if (enterList.indexOf(vInput.concat(', ')) != -1) {
valid = false;
alert('Already exist');
input.focus();
break;
}
enterList = enterList.concat(vInput.concat(', '));
}
if (!hasData) {
valid = false;
alert('No data to submit');
}
return valid;
}
</script>
Title:
Check unique input data to submit
Description:
<form name="f1" id="f1" onsubmit="return checkToSubmit();" method="post"> <input type=&q...
...
Rating:
4