javascript - Update global Array into function -


we build jquery ui datepicker @ first. later want update (refesh) one. highlighting dates color want change color refresh. build array colored dates want change array refresh after updates array => update dont work! why?

<script type="text/javascript">     var dates = {'2015/5/5':'highlight_red','2015/5/6':'highlight_red'};      function refreshcalendar (date, prozent) {         var year = date.getfullyear();         var month = date.getmonth();         var day = date.getdate();            var search = year+'/'+month+'/'+day;         if (search in dates) {             if (prozent == 100) {                 dates[search] = 'highlight_green';             } else {                 dates[search] = 'highlight_red';             }         }     }      refreshcalendar ('2015/5/5',100);      var erg;     (elem in dates) {         erg += elem+" => "+dates[elem];     }     alert(erg); </script> 

we wand chande die date 2015/5/5 red green array hate update ;-) in control-variable erg same after running funktion

jsfiddle

description: added parsing of date , initialized erg variable undefined isn't returned.

var dates = {'2015/5/5':'highlight_red','2015/5/6':'highlight_red'};  // parse date in yyyy/mm/dd format function parsedate(input) {     var parts = input.split('/');     // new date(year, month [, day [, hours[, minutes[, seconds[, ms]]]]])     return new date(parts[0], parts[1]-1, parts[2]); // note: months 0-based }  function refreshcalendar (date, prozent) {     //we have parse out date (real date object)     var parseddate = parsedate(date);     var year = parseddate.getfullyear();     var month = parseddate.getmonth();     var day = parseddate.getdate();        var search = year+'/'+month+'/'+day;     if (search in dates) {         if (prozent == 100) {             dates[search] = 'highlight_green';         } else {             dates[search] = 'highlight_red';         }     } }  refreshcalendar ('5/5/2015', 100); // have initialize erg since using += return undefined on first pass var erg = ''; (elem in dates) {     erg += elem + " => " + dates[elem]; } alert(erg); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -