My Code:
var cat, inputdat;
var KeyUrl = "someurl";
cat = ["abc", "def", "ghi"];
var fLen = cat.length;
for (i = 0; i < fLen; i++) {
inputdat += "<label for=\"" + cat[i] + "\">" + cat[i] + "</label><br><input type=\"text\" id=\"" + cat[i] + "\" name=\"" + cat[i] + "\" value=\"\"" + cat[i] + "\"><br><a href=\"" + KeyUrl + document.getElementById(cat[i]).value + "\" rel=\"nofollow\">Here</a><br>";
}
inputdat += "<br/>";
document.getElementById("res").innerHTML = inputdat;
<h2 id="res">hello</h2>
The error:
{ "message": "TypeError: document.getElementById(...) is null", "filename": "https://stacksnippets.net/js", "lineno": 19, "colno": 202 }```
Part of the code causing the error:
href=\""+KeyUrl+document.getElementById(cat[i]).value+"
I am trying to append the value of the input to my keyurl but I am getting null.