Answer the question
In order to leave comments, you need to log in
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)">
<input name="adds" type="image" src="/i/shortorder_send.png" onClick="sendformforyandex();">
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);
}
});
}
function yandex() {
yaCounter7613629.reachGoal('leftpanel');
return true;
}
function sendformforyandex() {
sendAnketa(num, num2);
yandex();
}
Answer the question
In order to leave comments, you need to log in
when the button is clicked, the function is called sendformforyandex
, which, in turn, calls sendAnketa(num, num2)
, where num
and num2
are not defined (equal to undefined
). in the course of a terrifying and monstrous check inside sendAnketa
, it turns out that none of if
them work, check
remains equal false
, the function execution is interrupted on this line:if(!check) return false;
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 questionAsk a Question
731 491 924 answers to any question