Devil's Advocate Devil's Advocate - 4 months ago 18
Javascript Question

Detect changed input text box

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. Entire page code below:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="DatabaseAssociation.aspx.vb" Inherits="projectname.DatabaseAssociation" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="add.css" rel="stylesheet" type="text/css" />
<script src="../JS/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="../JS/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script>

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

</head>
<body>
<form id="form1" runat="server">
<div>
<input id="inputDatabaseName">
<table id="searchResults"><tr><td>empty</td></tr></table>
</div>
</form>
</body>
</html>

Answer

You can use oninput event like this:

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

Or like this:

<input id="inputDatabaseName" onchange="youFunction();"
onkeyup="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();"/>
Comments