Chrome is showing error "cannot read property 'elements' of null" here is the code function DisplayFormValues(){ var str = 'proType=4&send=y'; var elem = document.getElementById('form2').elements; // error on this line for(var i = 0; i < elem.length; i++){ str += '&' + elem[i].name + '=' + elem[i].value; } //document.write(str); return str } Code (markup): What's this? How to fix? Please help