I just started to learn Js, these are still the first steps) I can’t find a mistake because I’m tired ..) But the script doesn’t work

$('document').ready(function(){ function system(){ var a1 =$('#value1').val(); if (a!=null){ alert('nese var sende nese var nese'); }else{ alert('Plist insert value '); } } $('button').on('click',system()); }) 

    2 answers 2

    1) document specified without quotes:

     $(document).ready(function(){...}); 

    2) $(document).ready(function(){...}); - this is not pure JS, so that it runs, you need to connect the Jquery library

    3) function system(){...} course, you can specify it in document ready , but usually it is passed for it:

     function system(){...}; $(document).ready(function() {...}); 

    4) Starting the function from the button can be done like this:

     $('button').on('click', system); 

    or so

     $('button').on('click', function() { system() }); 

    And this is also not pure JS, you need the Jquery library

    5) Your variables are listed differently:

     var a1 = $('#value1').val(); // Тут "a1" if (a!=null){ // тут "a" ... }else{ ... } 

    Change to

     var a1 = $('#value1').val(); if (a1 == null){ ... }else{ ... } 
    • Yes, I have already connected jquery - elik
    • @elik, well then one of the points :) - Yuri
    • well thanks!) - elik
    • @elik, I added another item - Yuri
    • ahh that's what the variables got confused)) understandable thanks friend - elik
     $('.button').on('click', function(){//Возможно, пропущен селектор класса '.', либо идентификатора '#' system(); //функции запускаются через анонимные }); 

    And yes, there the line is inconspicuous, but the names of the variables are different:

     var a1 =$('#value1').val(); if (a!=null){...} 

    a1 and a

    It seems to me that this is the root of the problem.

    • Пропущен селектор класса '.', либо идентификатора '#' - I will tell you a secret, there is a tag like <button> - Alexey Shimansky
    • @ AlekseyShimansky kk corrected, thanks - SLy_huh