Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect changed input text box

Tags:

jquery

input

I've looked at numerous other questions and found very simple answers, including the code below. I simply want to detect when someone changes the content of a text box but for some reason it's not working... I get no console errors. When I set a breakpoint in the browser at the change() function it never hits it.

$('#inputDatabaseName').change(function () {      alert('test');  }); 
<input id="inputDatabaseName"> 
like image 901
THE JOATMON Avatar asked May 27 '11 13:05

THE JOATMON


People also ask

How do you detect change in text input box?

Answer: Use the input Event You can bind the input event to an input text box using on() method to detect any change in it. The following example will display the entered value when you type something inside the input field.

How do you find the input value of change?

Use input change event to get the changed value in onchange event argument. If you bind using the two-way bind to value property, it will automatically change the value into the value property.


2 Answers

You can use the input Javascript event in jQuery like this:

$('#inputDatabaseName').on('input',function(e){     alert('Changed!') }); 

In pure JavaScript:

document.querySelector("input").addEventListener("change",function () {   alert("Input Changed"); }) 

Or like this:

<input id="inputDatabaseName" onchange="youFunction();" onkeyup="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();"/> 
like image 120
Ouadie Avatar answered Dec 08 '22 17:12

Ouadie


try keyup instead of change.

<script type="text/javascript">    $(document).ready(function () {        $('#inputDatabaseName').keyup(function () { alert('test'); });    }); </script> 

Here's the official jQuery documentation for .keyup().

like image 45
Scott Harwell Avatar answered Dec 08 '22 16:12

Scott Harwell