For each enter or for every entry into the text box I want the alert to be triggered
<input type="text" id="val_xml" class="val_xml1" maxlength="3" size="2"/>
$('#val_xml').bind('change',function() {
var v = $('#val_xml').val();
alert(v);
});
Thanks
Jean
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:
Try it out with this jsFiddle
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 thevalueproperty of a DOM element, which is why I usethis.value.References:
.attr().keyup().trigger()