I need to check the length of the text in a text box that has MaxLength set to 10. If someone pastes more than 10 characters the pasted text is trimmed to 10 characters. How can I detect if the pasted text was longer than 10 characters and let the user know 'your text has been trimmed'?
Also, if when someone pastes I put up an alert box, it triggers the onblur event, which occurs first. How can I prevent this?
<input type="text" id="txt" maxlength="10" onblur="checklength(event);" onpaste="pasted(this)">
function checklength(e)
{
alert('blurry ' + document.getElementById('txt').value.length);
e.cancelBubble=true;
}
function pasted(element) {
setTimeout(function(){
alert(element.value.length);
}, 0);
}
Beginning of a fiddle at enter link description here