I have some inputs (random number > 0) and each is inside a div with same class so I have this structure:
<div class="myclass"> <!-- div #1 -->
<input name="name" class="input">
<!-- other inputs that don't take care -->
</div>
...
<div class="myclass"> <!-- div #n -->
<input name="name" class="input">
<!-- other inputs that don't take care -->
</div>
I need to check that the value of every input doesn't match with other, so if I have in the first input myname
as value in the input n I can't have myname
.
I have the next JQuery code to iterate over all divs to extract the info about every div.
$('.myclass').each(function() {
input = $(this).find('input[name="name"]').val();
});
And then, it sends all info (JSON parsed before) through jQuery ajax to PHP scripts which MUST revalidate that input values don't be equal.
So, the question is: what's the best way to go over all divs and know if value is repeated? I thought about making a $.each inside the each I have to iterate over all elements but I don't know about its performance.
And what about with PHP script, what's the best way to afford it? Thank you.
NOTE: JSON parsed array, now have this structure:
{"user_info":{"app_id":0,"user_id":0},"contact":{"has_contact":0},"menu_items":[{"position":0,"name":"Nosotros","icon_id":"ic_delete_black_48dp.png","content":"nosotros"},{"position":1,"name":"Precios","icon_id":"ic_help_black_48dp.png","content":"nosotros"}]}
Don't worry about "user_info" and "has_contact" they are irrelevant, the name for which I was talking is the menu_items[index]['name'] value.