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">
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.
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.
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();"/>
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With