jquery - Javascript to validate hours per week/weeks per year entered -


i have html form allows users enter values both "number of hours per week" , "number of weeks per year". include check ensure users don't enter values exceed possible maximum - check "number of hours per week" not more 168 , "number of weeks per year" not more 52.

i have script calculates "average number of hours per week" based on values entered previous 2 inputs follows:

function calc(){      $('#lastyear tr:has(.risk)').each(function(i,v){          var $cel = $(v.cells);          var $risk = $cel.eq(1).find('option:selected').val();         var $numb = $cel.eq(2).find('input').val();         var $weeks = $cel.eq(3).find('input').val();         var $avg = ($numb * $weeks) / 52;         var $avgrounded = math.round( $avg * 10 ) / 10;          $cel.eq(4).find('input').val($avgrounded);      });    

i somehow need extend check inputs valid values , display dialog text if enter invalid value. i've setup jsfiddle here demonstrate form. i'm learning javascript go @ moment , stumped on one.

update: i've added code check number of hours i'm getting stuck in endless loop displays alert dialog box click ok , same alert dialog box. see updated jsfiddle:

 var hour=document.getelementbyid('hour').value;  var week=document.getelementbyid('week').value;  if(hour>168){alert ("error");return false;} else if(week>52){alert ("error");return false;} else{return true} 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -