I try to check if input value of email is the same with other input value of email.You can add persons like a accordian. So every person has an email. But it is not possible that two or more put the same email address in the text box
I have this:
$(document).ready(function() {
// Form validation
$(".klantregistratie form").validate({
rules: {
verploegen_form_klantregistratie_Bedrijfsnaam: "required",
verploegen_form_klantregistratie_Postcode: "required",
verploegen_form_klantregistratie_Plaats: "required",
verploegen_form_klantregistratie_Emailadres: {
required: true,
email: true
},
verploegen_form_klantregistratie_KvK_nummer: "required",
verploegen_form_klantregistratie_naam_eigenaar: "required",
verploegen_form_klantregistratie_Telefoon_mobiel: "required"
},
messages: {
verploegen_form_klantregistratie_Bedrijfsnaam: "De bedrijfsnaam is niet ingevuld",
verploegen_form_klantregistratie_Postcode: "De postcode is niet ingevuld",
verploegen_form_klantregistratie_Plaats: "De plaats is niet ingevuld",
verploegen_form_klantregistratie_Emailadres: {
required: "Je hebt geen email adres ingevuld",
email: "Je hebt geen geldig email adres ingevuld"
},
verploegen_form_klantregistratie_KvK_nummer: "Het KVK nummer is niet ingevuld",
verploegen_form_klantregistratie_naam_eigenaar: "De naam van de eigenaar is niet ingevuld",
verploegen_form_klantregistratie_Telefoon_mobiel: "Het (mobiele) telefoon nummer is niet ingevuld"
}
});
// Hide the textarea
$('#verploegen_form_klantregistratie_Contactpersonen').parent().parent().hide();
$('input[name=FormCH1_h]').val(x);
// Add extra contact clicked?
$('#add-contact p a').click(function() {
// Make a copy of the first input fields
html = $('#new-contact').children().clone();
// Get number of tabs in the accordion
var index = $('#accordion h3').length;
// Remove the values
html.find("input[type=text]").val("");
html.find('input[type=checkbox]').attr('checked', false);
// New 'id', 'for' and 'name' attribute names
html.find('input[type=checkbox]').each(function() {
me = $(this);
attr = me.attr('id');
number = attr.split('_')[2];
newNumber = parseInt(index) + 1;
newAttr = attr.replace(number, newNumber);
me.attr('id', newAttr).attr('name', newAttr).next().attr('for', newAttr);
});
// Insert it at the end
$('#accordion').append(html);
$('#accordion').accordion('refresh');
// Set last tab to active
$("#accordion").accordion({
active: index
});
// Cancel the click
return false;
});
// Submit clicked?
$('.submit-button input').click(function() {
// Set variables
var html = '';
var i = 1;
// Loop through all the input fields for contacts
$('#accordion .user-row').each(function(uindex, uvalue) {
html += '<tr>';
if (($('#contactpersonen-email').attr('value')) == $('#contactpersonen-email').attr('value')); {
alert('the same');
}
$(this).find('input').each(function(index, value) {
// Check if input type is a checkbox
if ($(this).is(":checkbox")) {
var JaNee = 'Nee';
if ($(this).is(":checked")) JaNee = 'Ja';
html = html + '<td>' + JaNee + '</td>';
} else {
// Add the value into the html
html = html + '<td>' + $(this).val() + '</td>';
}
});
html += '</tr>';
});
// Set the value from the textarea to the generated html
$('#verploegen_form_klantregistratie_Contactpersonen').val('<table>' + html + '</table>');
});
});
$(function() {
$("#accordion").accordion({
heightStyle: "content"
});
});
So I try to compare like this:
if (($('#contactpersonen-email').attr('value')) == $('#contactpersonen-email').attr('value')); {
alert('the same');
}
This also doesnt work:
if(($('#contactpersonen-email').val()) == $('#contactpersonen-email').val() )
{
alert('the same');
}
I have it now like this:
<![CDATA[
$(document).ready(function()
{
// Form validation
$(".klantregistratie form").validate({
rules: {
verploegen_form_klantregistratie_Bedrijfsnaam: "required",
verploegen_form_klantregistratie_Postcode: "required",
verploegen_form_klantregistratie_Plaats: "required",
verploegen_form_klantregistratie_Emailadres: {
required: true,
email: true
},
verploegen_form_klantregistratie_KvK_nummer: "required",
verploegen_form_klantregistratie_naam_eigenaar: "required",
verploegen_form_klantregistratie_Telefoon_mobiel: "required"
},
messages: {
verploegen_form_klantregistratie_Bedrijfsnaam: "De bedrijfsnaam is niet ingevuld",
verploegen_form_klantregistratie_Postcode: "De postcode is niet ingevuld",
verploegen_form_klantregistratie_Plaats: "De plaats is niet ingevuld",
verploegen_form_klantregistratie_Emailadres: {
required: "Je hebt geen email adres ingevuld",
email: "Je hebt geen geldig email adres ingevuld"
},
verploegen_form_klantregistratie_KvK_nummer: "Het KVK nummer is niet ingevuld",
verploegen_form_klantregistratie_naam_eigenaar: "De naam van de eigenaar is niet ingevuld",
verploegen_form_klantregistratie_Telefoon_mobiel: "Het (mobiele) telefoon nummer is niet ingevuld"
}
});
// Hide the textarea
$('#verploegen_form_klantregistratie_Contactpersonen').parent().parent().hide();
// Add extra contact clicked?
$('#add-contact p a').click(function()
{
// Make a copy of the first input fields
html = $('#new-contact').children().clone();
// Get number of tabs in the accordion
var index = $('#accordion h3').length;
// Remove the values
html.find("input[type=text]").val("");
html.find('input[type=checkbox]').attr('checked', false);
// New 'id', 'for' and 'name' attribute names
html.find('input[type=checkbox]').each(function () {
me = $(this);
attr = me.attr('id');
number = attr.split('_')[2];
newNumber = parseInt(index) + 1;
newAttr = attr.replace(number, newNumber);
me.attr('id', newAttr).attr('name', newAttr).next().attr('for', newAttr);
});
// Insert it at the end
$('#accordion').append(html);
$('#accordion').accordion('refresh');
// Set last tab to active
$("#accordion").accordion({ active: index });
// Cancel the click
return false;
});
// Submit clicked?
$('.submit-button input').click(function()
{
// Set variables
var html = '';
var i = 1;
// Loop through all the input fields for contacts
$('#accordion .user-row').each(function (uindex, uvalue) {
//Niels
var mails = $('.contactpersonen-email').map(function(){
return $(this).val();
//console.log($(this).val());
}).get();
Array.prototype.areUnique = function() {
var l = this.length;
for(var i=0; i<l; i++) {
for(var j=i+1; j<l; j++) {
if (this[i] === this[j]) return false;
}
}
return true;
};
if (!mails.areUnique()) {
alert('values are not unique');
} else {
alert('values are unique');
}
//Niels
But every time it says Vlaues are unique
I have it liket this:
// Loop through all the input fields for contacts
$('#accordion .user-row').each(function (uindex, uvalue) {
var mails = $('.contactpersonen-email').map(function(){
return $(this).val();
}).get();
console.log(mails);
["email 1"]
klant-worden:661 ["email 1"]