Nagesswara T Nagesswara T - 4 months ago 12
HTML Question

document.getElementById(fieldName).value; is not working in chrome and firefox

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.

Answer

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;
    }
Comments