W
W
wismel2017-10-11 12:17:08
JavaScript
wismel, 2017-10-11 12:17:08

What is the mistake made when specifying JS events and functions on the site?

The site has a form for sending data for feedback. I want to set up a JS event via onclick for Yandex metrics.
It originally looked like this

<input name="adds" type="image" src="/i/shortorder_send.png" onClick="sendAnketa(10)">

I change like this
<input name="adds" type="image" src="/i/shortorder_send.png" onClick="sendformforyandex();">

To these functions
function sendAnketa(num, num2){
    var check = false;
    if (num=="6" && num2=="_1") check = checkmailAndTel($('#a18_1').val(), $('#a19_1').val());
    if (num=="6" && !num2)  check = checkmailAndTel($('#a18').val(), $('#a19').val());
    if (num=="11" && !num2) check = checktext($('#a36').val(),'Имя') && checkmailAndTel($('#a37').val(), $('#a38').val()) && checktext($('#a39').val(),'Интересует');
    if (num=="9" && !num2)  check = checktext($('#a25').val(),'Тема') && checktext($('#a26').val(),'Текст');
    if (num=="7" && !num2)  check = checktext($('#a29').val(),'Ваше имя') && checkmailOrTel($('#a30').val()) && checktext($('#a32').val(),'Подробное описание');
    if (num=="5" && !num2)  check = checktext($('#a12').val(),'Имя') && checkmailOrTel($('#a13').val()) && checktext($('#a14').val(),'Текст сообщения');
    if (num=="4" && !num2)  check = checktel($('#a11').val());
    if (num=="10" && !num2) check = checktext($('#a33').val(),'Имя') && checktel($('#a34').val()) && checktext($('#a35').val(),'Интересует');
    
    
    if(!check) return false;
    var action="/kontaktnyy_blok/send"+num+".htm";
    var datas = $( "#ankform"+num+(num2?num2:"") ).serialize();

    $.ajax({
      type: "POST",
      url: action,
      data: datas,
      success: function(msg){
        $('#orderbanner_form').hide();
        $('#shadowdiv').show();
        $('#sendank_form').show().center();
        $('#sendank_text').html(msg);
      }
    });
  }

I add two such below
function yandex() {
  yaCounter7613629.reachGoal('leftpanel'); 
  return true;
  }
  
  function sendformforyandex() {
  sendAnketa(num, num2);
  yandex();
  }

But neither sending contact data to the mail, nor to the click info metric works.
I would really appreciate it if someone could point out where the error is.
Ps In JS, no boom boom, I did it according to the instructions, before that it worked, but there was a problem with this code.
Website rekmedia.ru feedback panel on the left

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
abberati, 2017-10-11
@wismel

when the button is clicked, the function is called sendformforyandex, which, in turn, calls sendAnketa(num, num2), where numand num2are not defined (equal to undefined). in the course of a terrifying and monstrous check inside sendAnketa, it turns out that none of ifthem work, checkremains equal false, the function execution is interrupted on this line:
if(!check) return false;

4
4mobile, 2017-10-11
@4mobile

the function should be called with sendAnketa(num, num2) parameters,
but here with what parameters is it called?
function sendformforyandex() {
sendAnketa(num, num2);
yandex();
}
so if(!check) return false;
at the first call, you need to look at what is returned here
if (num=="10" && !num2) check = checktext($('#a33').val().....
console.log to help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question