Ive been attempting to insert an input tag into the DOM with JavaScript.The problem arises when I set the innerHTML property of the input tag to some text.
One thing I noticed was that in Chrome developer tools the JavaScript generated input had a closing tag. Isn't the input tag a self closing tag?
When I checked developer tools I get no errors. Also, when I inspect the elements the input tag will appear along with the associated text but it will not appear on the window. Any idea, what causes this issue?
//javascript
function Survey() {}
Survey.prototype.displaySurvey = function() {
var form = document.createElement("form");
form.setAttribute("action", "none");
form.setAttribute("method", "get");
document.body.appendChild(form);
var input = document.createElement("input");
input.setAttribute("name", "prod");
input.setAttribute("type", "text");
input.innerHTML = "product";
form.appendChild(input);
}
window.onload = main;
function main() {
var survey = new Survey();
survey.displaySurvey();
}
<!DOCTYPE html>
<html>
<head>
<title>form test</title>
<script type="text/javascript" src="survey1.js"></script>
</head>
<body>
</body>
</html>
<input>'s do not haveinnerHTML- they have avalue