javascript - How do I grab the value from an html form input box as its being entered? -


How can I get value from an input box being logged?

A key will be turned on each time a release. Although this solution appears, there are some problems in it.

If users take the cursor with the arrows, then it has been triggered and you have to check yourself if the value of the field does not change.

If the user copies / pastes a value in the input field with the mouse, or the undo / click in the browser, the onkeyup has not been triggered.

Like in Mac or Google Docs, I did not want a Save button to submit the form to our app here. Any comments, or shortcuts are welcome because it is a bit overwhelming .

  1. Store the current value of onfocus , and start an interval to check the changes
  2. When the user takes something in input If there is a comparison with the old value,
  3. onblur , when the user moves away from the field, clear the interval and event handlers < / Li>

Here is the function I use, the elm input field is reference and when the value The change is then added callback function:

  & lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Then & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Input type = "text" onfocus = "changeField (this, fldChanged);" & Gt; & Lt; Script & gt; Function Change Field (after elm,) {var old, from, val, chk = function () {val = elm.value; If (old! & Val === elm.defaultValue) {old = val; } And if (Old! == wal) {Old = Val; After (elm); }}; Zach (); To = setInterval (chk, 400); Elm.onblur = function () {from & amp; Amp; (To) clearInterval; Elm.onblur = Null; }; }; Function fldChanged (Elm) {console.log ('changed in:' + elm.value); } & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -