As you have not shared your HTML code, I am unsure as to which of them is wrong, but one of these does not exist:
var str = document.getElementById("cal_preview").value;
var str1 = document.getElementById("year").value;
var str2 = document.getElementById("holiday").value;
var str3 = document.getElementById("cal_option").value;
There is either no element with the id cal_preview, year, holiday, cal_option, or some combination. Therefore, JavaScript is unable to read the value of something that does not exist. However, if you want to check that the element exists first, you could use an if statement for each:
var str,
element = document.getElementById('cal_preview');
if (element != null) {
str = element.value;
}
else {
str = null;
}
You could obviously change the else statement if you want or have no else statement at all, but this will vary with preference.