简体   繁体   English

在文本框中输入/输入数据时,将显示输入的值

[英]On typing/entering data in text box getting the entered value to display

I have a text box, after entering which i need to get that value and display in alert box,without using any forms or buttons. 我有一个文本框,输入后,我需要获取该值并显示在警报框中,而无需使用任何表单或按钮。

This is what I used: But its not working ,it gives null value on loading of the file. 这就是我使用的:但是它不起作用,它在加载文件时给出了空值。

HTML 的HTML

<tr>
    <td><br>Address of Patient</td>
    <td> <br> <input type="text" name="inc_patientAddress" id="inc_address" required></td>
</tr>

Jvascript 脚本

<script type="text/javascript">
var x = document.getElementById('inc_address');
alert(x.value);
</script>

I want to display the text box value after entering the data in text box , Is it possible? 我想在文本框中输入数据后显示文本框值,可以吗? Please help 请帮忙

Use blur event: 使用blur事件:

document.getElementById('inc_address').addEventListener('blur', function() {
    console.log(this.value);
}, false);

Demo: http://jsfiddle.net/tusharj/hop3szu4/ 演示: http//jsfiddle.net/tusharj/hop3szu4/

Docs: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener 文件: https//developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

Try this 尝试这个

For every input 对于每个输入

$('#inc_address').on('input', function() {
alert($(this).val());
});

Working Fiddle Here 在这里工作小提琴

For every complete Input 对于每个完整的输入

$('#inc_address').on('change', function() {
alert($(this).val());
});

Working Fiddle Here 在这里工作小提琴

You need to add blur function for that input. 您需要为该输入添加模糊功能。 As soon as it will lost focus from that text box it will call this function and so the alert will be displayed. 一旦它从该文本框中失去焦点,它将调用此函数,因此将显示警报。

<input type="text" name="inc_patientAddress" id="inc_address" onblur="myFunction()" required>

Call this funtion on blur: 将此函数称为模糊:

myFunction(){
      alert("#inc_address").value();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据使用javascript在另一个文本框中输入的值,自动在文本框中显示值 - Automatically display value in a text box based on the value entered in another text box using javascript 复选框打勾时,如何将在一个文本框中输入的数据显示到另一个文本框中? - How display data entered in one text box to another text box on checkbox tick? 根据在另一个文本框中输入的文本在文本框中显示文本 - Display Text in text box according to text entered in another text box 如何通过在某些情况下在第一个文本框中输入值来在第二个文本框中显示值 - How to display value in second text box by entering value in first for some condition 将在输入框中输入的文本显示到控制台 - display text entered in an input box to the console 在输入中输入数据,然后仅显示在页面上其他位置输入的文本 - Entering data in an input and then displaying just the text entered elsewhere on page 在输入文本框中输入的格式值 - Format value entered in input text box 如果输入数据,则清空文本框 - Empty the text box if data's are entered 如何计算文本框中输入的字符数并在其旁边自动显示? - How to count the number of characters entered in a text box and display it automatically next to it? JavaScript 用于根据 HTML 文本框中的值输入日期 - JavaScript for entering date based on value in an HTML text box
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM