As far as I can tell, getElementByName
is not a function. You can use getElementsByName
(note the plural). This will return a collection rather than an element. More than this, you were fetching the entire element, not the value of the element like it seems you want. The following works for me:
var name = document.getElementsByName("usrname")[0].value;
var comment = document.getElementsByName("comnts")[0].value;
document.write(name + "wrote "+ comment);
0
solved Why is this code working and not the other one? JavaScript