Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect when an input is changed?

Via JavaScript, PHP, or HTML. I want to do this to check if a username is allowed (on our side).

Sorry for not elaborating too much. If the username is too short, a message will appear next to it (I will do this part) saying that it is too short, but for this to be done automatically I would need for it to be detected.

<script type="text/javascript">
document.getElementById('username').onchange=userCheck;
function userCheck() {
    document.getElementById("usercheck").innerHTML="kk";
}
</script>

<form action="devlabs.php">
Username: <input type="text" id="username"/><em id="usercheck"></em>
</form>
like image 953
Anonymous the Great Avatar asked Jun 24 '10 22:06

Anonymous the Great


1 Answers

What you are looking for is the onChange event. For example, if you were using prototype.js, the following would do the trick:

$('usernameFieldId').observe('change', usernameValidaitonFunction);
like image 138
pkaeding Avatar answered Nov 08 '22 20:11

pkaeding