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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a7da-2c1fd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a7da-2c1fd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?