How to get the value of input in real time by js

    
        <button></button>
    </body>
</html>

the input value obtained each time is empty, and the value entered manually is also empty. What"s going on

Mar.11,2021

window.onload = function() {
                var buttonClick = document.getElementsByTagName('button')[0]; 
                buttonClick.onclick = function () {
                     var cellPhone = document.getElementsByTagName('input')[0].value;
                     var age = document.getElementsByTagName('input')[1].value;
                    if (cellPhone == "" || isNaN(cellPhone)) {
                        alert('');
                    }
                }
            }

you read the edit box under the window.onload event, that is, when the page is loaded, and the content of the edit box is still empty. You should read it in the submitted click event.

window.onload = function() {
    var buttonClick = document.getElementsByTagName('button')[0]; 
    
    buttonClick.onclick = function () {
         var cellPhone = document.getElementsByTagName('input')[0].value;
         var age = document.getElementsByTagName('input')[1].value;
        if (cellPhone == "" || isNaN(cellPhone)) {
            alert('');
        }
    }
}

what you need is not real time, you just need to get the value after clicking the button.
your current cellPhone is taken before it is clicked, so how is it possible to get it--

  http://www.jb51.net/article/9.

Menu