How to write a jquery function that can return 3 possible options -


i have basic points counter widget working on. had earlier question got answered me moving. have final question. basically, have function going return true or false, need third option.

the logic is:

  • if input char count in range, user gets points
  • if user edits , count stays in range no new points
  • if user edits , count goes out of range after in range, user looses points

i think hve right, not sure how complete function.

http://jsfiddle.net/jntja/8/

 var check = false;   function titleinc() {      var length = $('#title').val().length;      if (length >= 5 && length <= 10 && !check) {          check = true;          return true;      } else if (check  && length < 5 && length > 10) {          // set function return decrement      } else {          return false;      }       $('#title').blur(function () {          var current = parseint($('#end_val').val(), 10);          if (titleinc()) {              $('#end_val').val(current + 12);          } else if(  ){          // there needs way decrement          }      });   }); 

var options = {          increment: 1,          decrement: 2,           donothing: 3      };   function titleinc() {      var length = $('#title').val().length;      if (length >= 5 && length <= 10 && !check) {          check = true;          return options.increment;      } else if (check  && length < 5 && length > 10) {          return options.decrement;      } else {          return options.donothing;      }       $('#title').blur(function () {          var current = parseint($('#end_val').val(), 10),              option = titleinc();          if (option === options.increment) {              $('#end_val').val(current + 12);          } else if(option === options.decrement){              $('#end_val').val(current - 12);          }      }); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -