The user enters his id in the field, I need to in the course of writing this id to display information about it. But the fact is that this id has a different character size, and if you make requests each time you press a key, then it seems to me that this is bad) So how else can you do it? There is an option when moving to another field, but suddenly he will fill this field last (Advise. But if there are no other options, at least tell me how to determine what the user switched to another field)
3 answers
The check can be done X seconds after the input is stopped.
<script type="text/javascript"> timer = { delay: 1000, event: function(){ //То что вы хотите }, restart: function (){ this.stop(); this.id = setTimeout( this.event, this.delay ); }, stop: function (){ clearTimeout( this.id ); }, id: 0 }; </script> <input onchange = "timer.restart();"> - Oh, good idea. Just how to implement it? Each time a key is pressed, it takes seconds to check, but I don’t know how to do it (Of course, it is clear that onkeyup - iproger
- Added code in response. - timka_s
And this is not a posting to Google, but simply an advice to do as they have. Since it is difficult to come up with a more intuitive and simple solution for displaying information at the time of the search.
You can do it synchronously with the input, you can - with a slight delay, so as not to annoy. But since the ajax-запрос will be executed for some time, you can make the delay irrelevant.
As an alternative - see how convenient the hint for tags on stackoverflow.com was made when asking a question.
- Those. nothing serious to request every keystroke? (I don’t bother mysql) A good idea was born: if the user is now in the input field, go, then make a request every 3 seconds) Tell me, can you tell me if he is in the input field or not? Maybe there is some event Onunactive)) - iproger
- @mctrane Yes, do for each press, only after a very short pause. Google does something, I think your scale is smaller. - Costantino Rupert
- Thank you very much. I will choose) - iproger
- By the way, I also strained the autocomplex (especially when I selected 500 records at a time), I started to store the cache in the session, the query speed increased every 20. - culebre
If it doesn’t matter to you where to display info, then use autocomplete:
The second plugin has much more features. The ability to set the delay and many other interesting options is present in both plugins.
- I hate to use a whole library for simple tasks) I love all my code) But thanks all the same ) - iproger
- Well then reinvent the wheel =)) - culebre