I have created a form where user inputs the minimum and maximum number of textareas that can be added to a page. It generates the code below in order to pick it up with JScript:
$minimum .= '<div id="K'.$i.'">'.$min[$i].'</div>';
$maximum .= '<div id="H'.$i.'">'.$max[$i].'</div>';
In JScript, I defined a loop that will catch the above div tags and theirs innerHTMLs as numbers and put it in an array.
var mincount = [];
var maxcount = [];
for(var k=1; k<101; k++) {
mincount[k] = parseInt(document.getElementById("K"+k).innerHTML, 10);
maxcount[k] = parseInt(document.getElementById("H"+k).innerHTML, 10);
}
The k is defined to be up to 100. So, I know this is the problem, because then if there are less then 100 textareas, the getElementById is having null values.
So, it gives error: Uncaught TypeError: Cannot read property 'innerHTML' of null
But it must be defined to be up to 100. So, is there any option that can work something like this:
if(mincount[k] == null) {mincount[k] = ""} // in order to avoid null values.
This isn't working. It still get an error.
$minand$maxarrays directly to a data attribute or even a javascript variable.