There is an input (invisible). When text entry begins, the capress event causes a focus event on the input, into which everything that is entered from the keyboard is transmitted. then the variable "value_input" gets the value from the ipput and is compared with the base.

The problem is that all this is triggered by a capres event, that is, for example, if someone enters eight characters, there will be eight checks in the database. And you need to do just one check. That is, you need to know that input to the input is complete, and then start the check.

How do I know that input to the input is complete, and then perform just one check?

Suppose that in order to find out that the input is complete, I wrote a function, but then the problem is: how to call this function?

If the check function is called at each event by a capress, then it is not suitable, it is necessary only at the first one.

How to implement it correctly?

  • "How do I know that input to input is complete?" - you can check input.value.length - Stack
  • Ajax validation happens this way ... with every spell. Only more likely the keyup and not the keypress ....... can still be keypress .. but there is no guarantee that the focus from the keyup will be keyup - Alexey Shimansky
  • @ Alexey Shimansky For everyone I don’t need. This is not an ordinary check you need to know when the user has finished typing and only then compare. And not with each character typed. - Dementiy1999
  • @ Dementiy1999 is impossible. You do not know the user's thoughts. Maybe he typed. then thought. went tea drank, continued to recruit. went to the toilet. then he came to his mind and erased everything and began to write again. then the girl came and they went in for passionate sekis. and then I remembered that he didn’t fill out and did not finish the prelude, he finished writing the characters and sent ......... then setTimeout to check the input then - Alexey Shimansky
  • @ Dementiy1999 I can suggest an option, I don’t know how safe it is: When you access a page with a form, you access the database, from which the necessary data are drawn and are temporarily added to a certain session variable. During validation, the value is compared with the data in this variable, pulling only it .... after finishing work with the form, the data from that variable must be cleared and forgotten - Alexey Shimansky

1 answer 1

There is for example such a wonderful js framework knockoutjs

This framework has an entity called Observables.

What you want to do is out-of-the-box with this framework.

I recommend reading this.

I also advise you to look at the HelloWorld example. In essence, he does what you want.

Example:

 <p>First name: <input data-bind="value: firstName" /></p> <p>Last name: <input data-bind="value: lastName" /></p> <h2>Hello, <span data-bind="text: fullName"> </span>!</h2> // Here's my data model var ViewModel = function(first, last) { this.firstName = ko.observable(first); this.lastName = ko.observable(last); this.fullName = ko.pureComputed(function() { // Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName. return this.firstName() + " " + this.lastName(); }, this); }; ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes Knockout get to work 

You can poke here

  • So this is the usual work onblur or a reaction to enter . And the vehicle needs to be exactly when the person has finished recruiting. And how do you know when the user finished typing?)) - Alexey Shimansky
  • @ Alexey Shimansky you poked an example? - Mstislav Pavlov
  • Of course. Did I miss something? the text changes only when the focus goes away .... or I slapped the enterter ....... what I wrote above ... do the same work onblur and catch the enterter code And connect the whole framewave for such a task is irrational . - Alexey Shimansky
  • @ Alexey Shimansky, if you poke it, you might have noticed that your text below changes only when you have removed the selection from the input. Also, if you looked into the documentation, there is such a thing: myViewModel.fullName.extend({ rateLimit: 50 }); Will notify about the parameter change every 50ms - Mstislav Pavlov
  • So I'm talking about that. onblur not rational instead of connecting the framewave? + put setInterval - Alexey Shimansky