javascript - HTML moving from last input field to first -


i have several input fields this

<div class='kary rounded5' id='boarvariables'>     <span class='bld'>boar variables</span><br>     <div class='klbl'>number of boars tested</div>      <input type='text' id='k_nobt'><br>     <div class='klbl'>avg sperm/boar/week (lifetime)</div>      <input type='text' id='k_asbw'><br>     <div class='klbl'>sperm per dose (bil)</div>      <input type='text' id='k_spdb'><br>     <div class='klbl'>utilization rate</div>      <input type='text' id='k_ur'>%<br>       <div class='klbl'>boar productive lifetime (months)</div>      <input type='text' id='k_bplm'><br>          <hr>     <div class='klbl'>doses possible/week:</div>     <div class='kanswer' id='k_dpw'></div><br>     <div class='klbl'>doses actual/week:</div>     <div class='kanswer' id='k_daw'></div><br>           <div class='klbl'>usable doses/lifetime:</div>     <div class='kanswer' id='k_udl'></div><br>               <div class='klbl'>sows served/lifetime:</div>     <div class='kanswer' id='k_ssl'></div><br>       </div> 

i have enter working tab, , when press enter moves next input field, , calls function calculations on input.

    $('#boarvariables input').keypress(function(e) {         if (e.which == 13) {             $(this).nextall('input').first().focus();              e.preventdefault();         }     });                  $('#boarvariables input').blur(function(){         calcboarvars();     }); 

when last input field, can't figure out how move first field, trigger calculation correctly via blur.

i've tried variations of (inside of capturing enter) no luck

$('#boarvariables input:last-child').each(function(){     var $this = $(this);     $('#boarvariables input:first').focus(); }); 

 $('#boarvariables input').keypress(function(e) {         if (e.which == 13) {             if(!!$(this).nextall('input').first().length){                 $(this).nextall('input').first().focus();             }             else{                //i can't figure out how move first field : how                 $('#boarvariables input:first').focus();             }             e.preventdefault();         }     });  // trigger calculation correctly via blur : does.             $('#boarvariables input').blur(function(){alert("ok");}) 

demo : http://jsfiddle.net/zurze/


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -