$(document).ready(function(){ $('#phone').on('keyup',function(){ var pattern = new RegExp('[0-9]'); var counter=0; var val = $(this).val(); var spaceflag = true; }); $('#check_all').on('change', function(){ if($(this).is(":checked")){ $('[name="application[regulation]"]').prop('checked',true); $('[name="application[regulation_2]"]').prop('checked',true); $('[name="application[regulation_3]"]').prop('checked',true); $('[name="application[marketing]"]').prop('checked',true); $('[name="application[marketing2]"]').prop('checked',true); } else{ $('[name="application[regulation]"]').prop('checked',false); $('[name="application[regulation_2]"]').prop('checked',false); $('[name="application[regulation_3]"]').prop('checked',false); $('[name="application[marketing]"]').prop('checked',false); $('[name="application[marketing2]"]').prop('checked',false); } }); $("input[type=checkbox]:not(#check_all)").on('click', function(){ $('#check_all').prop("checked",false) console.log($('#check_all').prop('checked')); }); $('label').on('click',function(){ console.log('onclick label'); var target = $(this).attr('data-target'); console.log((target)); if(typeof target != 'undefined') { $('.mem-prev').css('display','none'); $(target).css('display','inline-block'); } }) $('#answer-input').on('keyup',function(){ $('#answer_limit').html(200-$(this).val().length); }) $('#answer_limit').html(200-$('#answer-input').val().length); $('#answer-input').keyup(); $('[name="application[email][first]"]').on("change",function(){ var val = $(this).val(); var firstEmailVal = $('[name="application[email][first]"]').val(); var secondEmailVal = $('[name="application[email][second]"]').val(); if(val !== '' && !validateEmail($(this).val())){ $('#td_email_first').html("Błędny format adresu email"); $(this).addClass("danger"); }/*else if((firstEmailVal !== '' && secondEmailVal !== '') && firstEmailVal !== secondEmailVal){ $('#td_email_first').html("Podane adresy email nie są identyczne");; $(this).addClass("danger"); }*/else{ $('#td_email_first').html(""); $(this).removeClass("danger"); } $('[name="application[email][second]"]').change(); }) $('[name="application[email][second]"]').on("change",function(){ var val = $(this).val(); var firstEmailVal = $('[name="application[email][first]"]').val(); var secondEmailVal = $('[name="application[email][second]"]').val(); if(val !== '' && !validateEmail($(this).val())){ $('#td_email_second').html("Błędny format adresu email"); $(this).addClass("danger"); }/*else if((firstEmailVal !== '' && secondEmailVal !== '') && firstEmailVal !== secondEmailVal){ $('#td_email_second').html("Podane adresy email nie są identyczne");; $(this).addClass("danger"); }*/else{ $('#td_email_second').html(""); $(this).removeClass("danger"); } $('[name="application[email][first]"]').change(); }) $('button.przycisk').on('click', function () { if($(this).prop('disabled')){ return; } $(this).addClass('submitted'); $(this).prop('disabled',true); $('form').submit(); }) }); function compareEmails(){ var firstEmailVal = $('[name="application[email][first]"]').val(); var secondEmailVal = $('[name="application[email][second]"]').val(); if((firstEmailVal !== '' && secondEmailVal !== '') && firstEmailVal !== secondEmailVal){ $('#td_email_first').html("Podane adresy email nie są identyczne"); $('#td_email_second').html("Podane adresy email nie są identyczne"); $('[name="application[email][first]"]').addClass("danger"); $('[name="application[email][second]"]').addClass("danger"); }else{ $('#td_email_first').html(""); $('#td_email_second').html(""); $('[name="application[email][first]"]').removeClass("danger"); $('[name="application[email][second]"]').removeClass("danger"); } } function validateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); }