javascript find duplicate string in array if there is duplication page not post but after show alert page is post ..so how to avoid
This Is My Code Of Javascript
$("#category").on('submit', function (e) {
debugger;
var Category1 = $("input[name='[0].Category']").val();
var Category2 = $("input[name='[1].Category']").val();
var Category3 = $("input[name='[2].Category']").val();
var Category4 = $("input[name='[3].Category']").val();
var Category5 = $("input[name='[4].Category']").val();
if (Category1 == "") {
swal("Category Must Be enter");
return false
}
if (Category2 == "") {
swal("Category Must Be enter");
return false
}
if (Category3 == "") {
swal("Category Must Be enter");
return false
}
if (Category4 == "") {
swal("Category Must Be enter");
return false
}
if (Category5 == "") {
swal("Category Must Be enter");
return false
}
//This Is Code For Duplication
var names = [Category1, Category2, Category3, Category4, Category5];
var uniqueNames = [];
$.each(names, function (i, el) {
e.preventDefault();
if ($.inArray(el, uniqueNames) === -1) {
uniqueNames.push(el);
}
else {
swal("Duplication Not Allow");
return false;
}
});
})
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Dr.Ajay KashyapPosted Feb 9, 2017, 5:46 AM
Manas Mohapatra Sir i solve that problem but thks for replay
Manas MohapatraPosted Feb 9, 2017, 5:43 AM