[Javascript] onChange event not firing at all

Andre Polykanine andre at oire.org
Wed Oct 20 11:49:09 CDT 2010


Hi everyone,
Here's a simple form. For unknown reason the onChange event does fire
only when the Tab key is pressed (as if it was an onBlur handler).
More than that, the remaining chars number is increasing only by one.
Any ideas, please?
Here's the code. I'm using jQuery 1.4.3.


<script type="text/javascript">
$(function() {
$("#note").validate({
rules: {
utext: {
required: true,
maxlength: 140
}
},
errorClass: "errmessage",
messages: {
utext: {
required: "Please write a note!",
maxlength: "The note might not be longer than 140 chars!"
}
}
});

var remainingChars=140;
var noteLength=0;
$("#counter").val(remainingChars);
$("#utext").change(function(event) {
noteLength=$(this).length;
remainingChars-=noteLength;
$("#counter").val(remainingChars);
});

$("#submitbutton").show();
$("#nojavascript").hide();
});
</script>

<form id="note" name="note" action="<?=$_SERVER['SCRIPT_NAME']?>">
<fieldset>
<legend>Leave me a note:</legend>
<textarea id="utext" name="utext" rows="3" cols="50"></textarea>
Chars remaining: <input type="text" id="counter" name="counter" size=3 readonly="readonly">
</fieldset>
<p id="submitbutton" class="signup" style="display:none"><input type="submit" name="addnote" id="addnote" value="Put the note"></p>
<p id="nojavascript" class="errmessage">If you're seeing this message, then you have disabled JavaScripт support. In order to have all functionality on our website, you must enable JavaScript support.</p>
</form>

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion



More information about the Javascript mailing list