document.getElementById (fieldName) .value; does not work in Chrome and Firefox

advertisements

Following javascript in HTML is working in IE browser. But, when i execute in Chrome and Firefox browser is not working.

var LastName = GetValueofField("txtName");

function GetValueofField(fieldName)
    {
        return document.getElementById(fieldName).value;
    }

please help me.


It is working fine...

Fiddle

<input type="text" id="txtName" value="TestData">

var LastName = GetValueofField("txtName");
function GetValueofField(fieldName)
    {
    console.log(document.getElementById(fieldName).value)
        return document.getElementById(fieldName).value;
    }