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

After inputting a value into one input, can it be assigned to another input immediately? _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:24:332002browse

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?


Reply to discussion (solution)

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>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn