Home >Web Front-end >HTML Tutorial >After inputting a value into one input, can it be assigned to another input immediately? _html/css_WEB-ITnose
78569ad79f80041f1474cbdc5364d3dd
c86a37d73a35bddfaeed5905a2074b9d
There are two input boxes on the page. The first input box can only input positive integers. When the value is entered in the first input box, can the second input box immediately obtain the value of the name1 input box?
How to achieve it?
onkeypress event
Thanks to the brothers upstairs, the effect I want can be achieved as follows:
<html><body><script type="text/javascript">function tests(e){var keynumvar keycharif(window.event) // IE { keynum = e.keyCode }else if(e.which) // Netscape/Firefox/Opera { keynum = e.which }//alert(keynum);keychar = String.fromCharCode(keynum)//alert(keychar);var obj = document.getElementById("id2");obj.innerText=keychar;}</script><form>Type some text (numbers not allowed):<input type="text" name="name1" onkeypress="return tests(event)" /><input type="text" name="name2" id="id2" /></form></html>