Your code seems to work.
Make sure to include a doc ready / Script tags, etc. And if you want an automatic alert once the maximum number of characters are entered:
$(function() {
$('#val_xml').bind('change',function() {
alert(this.value);
// These alerts can get annoying. If you are done with it, unbind it:
// $(this).unbind(arguments[0]); // <== would unbind this alert
});
// Check if max chars entered at each keyup
$(document).keyup(function() {
var $valXML = $("#val_xml");
if ($valXML.val().length >= $valXML.attr("maxlength") )
$valXML.trigger("change");
});
});
The above does one alert for each "entry". This means that the alert is triggered by blurring, by pressing enter, or when 3 chars (the max) are entered.
Note that each time you write $('#val_xml') you create a new jQuery object. So in your code, you create the exact same jQuery object twice. Additionally, there's no need to use a jQuery method to access the value property of a DOM element, which is why I use this.value.
References:
.attr()
.keyup()
.trigger()