for(i=0;i<formInfo['elementCount'];i++){
formElement = document.createElement('input');
formElement.type = 'text';
formElement.name = formInfo['elementName'][i];
formElement.setAttribute("value",formInfo['elementValue'][i]); // <-this part
console.log(formElement);
newForm.appendChild(formElement);
}
The above code does not work if I use:
formElement.value=formInfo['elementValue'][i];
console.log()
returns <input type="text" name="abc">
(value attr is missing)
but it works if
formElement.setAttribute("value",formInfo['elementValue'][i]);
console.log()
returns <input type="text" name="abc" value="123">
Why is the formElement.value
method not working?
Checked this with both chrome and ff and both have the same results