The problem is "& mestor =" + mestor,

like the documentation is all right

var btn = document.querySelectorAll("a"); for (var i=0;i<btn.length;i++){ btn[i].addEventListener("click", function() { var mesta = this.getAttribute('data'); var mestor = 0; switch (mesta) { case "1": var mestor = "Шапка сайта"; break; default: var mestor = "Не знаю"; } }) } $("#contactForm").validator().on("submit", function (event) { if (event.isDefaultPrevented()) { // handle the invalid form... formError(); submitMSG(false, "Пожалуйста заполните все поля"); } else { // everything looks good! event.preventDefault(); submitForm(); } }); function submitForm(){ // Initiate Variables With Form Content var name = $("#name").val(); var email = $("#email").val(); var phone = $("#phone").val(); $.ajax({ type: "POST", url: "php/form-process.php", data: "name=" + name + "&email=" + email + "&phone=" + phone + "&mestor=" + mestor, success : function(text){ if (text == "success"){ formSuccess(); } else { formError(); submitMSG(false,text); } } }); } function formSuccess(){ $("#contactForm")[0].reset(); submitMSG(true, "Ваша заявка отправлена ! С вами свяжется наш менеджер") } function formError(){ $("#contactForm").removeClass().addClass('shake animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){ $(this).removeClass(); }); } function submitMSG(valid, msg){ if(valid){ var msgClasses = "h3 text-center tada animated text-success"; } else { var msgClasses = "h3 text-center text-danger"; } $("#msgSubmit").removeClass().addClass(msgClasses).text(msg); } 
  • And the question is what? - Mikhail Vaysman
  • @MikhailVaysman "& mestor =" + mestor, not transmitted monosnap.com/file/PiZjHNQ7JDNE1KzokfMPRJhlI00cEC - Andry Lomakin
  • The code in the picture and in the question is different - Mikhail Vaysman
  • @MikhailVaysman I’m already a shaman and don’t know what to do - Andry Lomakin
  • read this How to ask questions and this tour - Mikhail Vaysman

2 answers 2

You have a problem with the scope with this variable, it is only in the function of the click handler.

 var btn = document.querySelectorAll("a"); var mestor = 0; for (var i=0;i<btn.length;i++){ btn[i].addEventListener("click", function() { var mesta = this.getAttribute('data'); switch (mesta) { case "1": mestor = "Шапка сайта"; break; default: mestor = "Не знаю"; } }) } 

    Make the global variable for the entire file, and pass the date in the request through the object as simple as:

     var data = { name: $("#name").val(); email: $("#email").val(); phone: $("#phone").val(); mestor: mestor } 

    І send to request

     $.ajax({ type: "POST", url: "php/form-process.php", data: data,