javascript - Submit textvalue when 5 seconds have passed -
im havind small problem code. problems solved , can't alone because not know goes wrong.
im trying make form 2 textboxes, when 1 textbox full (when there no activity in textbox 5 seconds) want skip second textbox. same deal here after 5 seconds without activity want form submit.
this have far, think got pieces of puzzle no intructions put together.
this got far:
function checkfields() { var inhoudlocatienummer = document.formsubmit.locatienummer.value; var inhoudbonnummer = document.formsubmit.bonnummer.value; document.formsubmit.locatienummer.focus(); //delay(checkfields, contains, 500 ); if (contains(inhoudbonnummer, "u") == true){ exceptionmessage("uitbesteed werk!"); } else{ <!--geen uitbesteed werk dus kan op de normale manier verzondern worden--> exceptionmessage("normale bon!"); } } var delayrec = {}; function delay(callback, id, calldelay) { cleartimeout(delayrec[id]); delayrec[id] = settimeout(callback, calldelay); } function contains(variable, value) { if (variable.indexof(value) >= 0) { return true; } } function exceptionmessage(errormessage) { alert(errormessage); }
can me or point me right direction.
the problem im having textbox isnt waiting inactivity skips keyup event gets triggered.
try one:
var timeoutobj; $( ":input" ).keyup(function( event ) { var _this = $(this); if(_this.val().length === parseint($(this).attr("maxlength"))){ timeoutobj = settimeout( function(){ _this.next('input').focus(); }, 5000); }else{ cleartimeout(timeoutobj); } }).keydown(function( event ) { //prevent entrer key if ( event.which === 13 ) { event.preventdefault(); } });
<form action="#" method="post"> <input name="input1" id="input1" placeholder="value1" maxlength="4"/> <input name="input2" id="input2" placeholder="value2" maxlength="10"/> <input name="input3" id="input3" placeholder="value3" maxlength="3"/> </form>
https://jsfiddle.net/hg1db2sp/1/
change $(this).next('input').focus(); ajax submit request.
Comments
Post a Comment