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
Release: 2016-06-24 12:24:33
Original
2000 people have browsed it




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>
Copy after login

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template