There is a vlll variable that gets a value from the input. How to make it so that, for example, the first time when checking an input, for example by a click, it retains the value, and during the second check it compared the first value with the second, and if it is not equal to something there?

to an input I address so:

 var vlll = $("#scanInput").val(); 

    3 answers 3

    The detailed answer of the @NeedHate sentence. During the first check, you can save the “initial” value of the element in its data-... attribute, for example. So:

     // по первому клику, например: // var vlll = $("#scanInput").val(); $("#scanInput").data('initial', $("#scanInput").val()); 

    Then in subsequent comparisons:

     // по другому событию, не первому: if( $("#scanInput").data('initial') == $("#scanInput").val()) { // равны } else { // не равны } 

    You can improve a lot: cache jQuery element; put everything in one handler then the first call from the subsequent ones will differ in the absence of a value in .data('initial') , or you can also set a second value to mark a non-first call: .data('notfirst', true) and check it .

      You can add a data-storage parameter to the tag, for example. And let's say there will be data-storage = "100". And compare with the values ​​in this parameter.

        It is also possible to use a closure. Below is the JavaScript code.

         function getValue() { "USE STRICT"; var prev; return function () { "USE STRICT"; var current = document.getElementById("task").value; if (current === prev) alert("They are equal"); else alert("They are not equal"); prev = current; return false; }; } function init() { "USE STRICT"; document.getElementById("theForm").onsubmit = getValue(); } window.onload = init;