javascript error : periodLookup[periodStr] is undefined, why is it throwing this error?
i have this method:
set_period_help_text: function(periodInput){
var metric = Monit开发者_JAVA百科orMetric.getSelectedMetric();
var periodStr = $('select[name=metric_period]').val();
var datapoints = Number(periodInput.attr("value"));
var period = datapoints * periodLookup[periodStr][0];
}
var periodLookup = {
"OneMinute": [1, "minute"],
"FiveMinute": [5, "minute"],
"OneHour": [1, "hour"],
"OneDay": [1, "day"],
"OneWeek": [1, "week"]
};
where var periodStr is being retrived from a dropdown menue that only has the values:
"OneMinute"
"FiveMinute"
"OneHour"
"OneDay"
"OneWeek"
i get a java script error when the page loads:
periodLookup[periodStr] is undefined [Break on this error] var period = datapoints * periodLookup[periodStr][0];
what is periodStr
's value? when it throws? i bet it doesn't contain what you think. possible reasons are multiple, like you're running the code before the DOM is ready.
精彩评论