ruby on rails - Want to change the value of something if its greater than or equal to something in javascript -


question have couple of text fields in rails app based off user's anv date date want compare date pick text box leave_start. have happen if choose leave_start date greater or equal anv date year change future text box 'yes' if leave start date less or equal anv change future text box 'no'. i've tried couple different ways each time no matter date pick changes future 'no' if date greater user's anv. appreciated!!!

*side note datepicker default format dateformat: 'mm-dd-yy' leave_start text field.

here application.js

 $(document).ready(function(){      $('#leave_start').change(function() {          var anv = $('.anv').val();          var l_start = $('#leave_start').val();          if (l_start >= future) {            $('#future').val('yes');         } else if (l_start <= future ) {            $('#future').val('no');         }     });  }); 

and here view

 #this var anv...    %td.lt= f.text_field :grab_date, :id => 'anv', :class => 'anv', :value => @grab_adj.strftime('%m-%d-%y')     #this var l_start...   %td.lt.feed= f.text_field :leave_start,  :label => false, :id => 'leave_start', :input_html => {:value => ''}     #this future text box want change 'yes' or 'no'   %td.lt.feed= f.input_field :future, :as => :select, :id => 'future', :class => 'future', :label => false, :collection => ["yes", "no"] 

first thing don't use 2-digit year format discussed cause of popular bug y2k bug. before comparing dates convert dates milliseconds compare.

  $(document).ready(function(){    $('#leave_start').change(function() {     var anv_date = date.parse($('.anv').val()); // date in milliseconds    var l_start_date = date.parse($('#leave_start').val()); // date in milliseconds      if (l_start_date >= anv_date) {        $('#future').val('yes');     } else if (l_start_date <= anv_date ) {        $('#future').val('no');     }    }); }); 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -