There is anyway to call a js function only when we fill a number of characters characters on a textfield?
from now im using onblur="myFunction();" but i wants to cal that function after we have some characters filled.
Thank you!
There is anyway to call a js function only when we fill a number of characters characters on a textfield?
from now im using onblur="myFunction();" but i wants to cal that function after we have some characters filled.
Thank you!
Share Improve this question edited Jul 20, 2013 at 0:54 dana 18.2k7 gold badges68 silver badges90 bronze badges asked Jul 20, 2013 at 0:41 FbInfoFbInfo 1032 silver badges7 bronze badges2 Answers
Reset to default 6Use the onkeyup
event:
let element = document.querySelector('your element');
element.onkeyup = function () {
if (this.value.length > 10) {
myFunction();
}
}
You also use this in an attribute:
<textarea onkeyup="if (this.value.length > 10) myFunction();"></textarea>
EXAMPLE (for both)
/* go automatic do the next tabindex */
$(":input:not(:disabled)").not($(":button")).keyup(function(evt){
if (this.value.length == 1) {
currentTabindex = $(this).attr('tabindex');
if (currentTabindex) {
nextInput = $('input[tabindex^="'+ (parseInt(currentTabindex)+1) +'"]');
if (nextInput.length) {
nextInput.focus();
return false;
}
}
}
});