N K N K - 5 months ago 17
HTML Question

Javascript runtime Object doesn't support this property error

I have a javascript function which get's me the

emailID
of the respective text added.

But what happens if the
EmailID
doesn't exist's it gives me error as


Microsoft JScript runtime error: Object doesn't support this property or method


Here is the function.

function getEmailIdByType() {
StrPriFnName = "FunGetEmailIdByType(" + document.getElementById('TxtPartyName').value + ")";
var ObjPriXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP")
ObjPriXMLHTTP.open("GET", "FrmInwardXMLHTTP.aspx?para=" + StrPriFnName, false);
ObjPriXMLHTTP.send("");

if (Trim(ObjPriXMLHTTP.responseText) != "") {
var StrPriData = ObjPriXMLHTTP.responseText.Split('~');
document.getElementById('TxtEmail').value = StrPriData[1];
}
else {
return false;
}
}


It gives me error at line:-

var StrPriData = ObjPriXMLHTTP.responseText.Split('~');

Answer
if (Trim(ObjPriXMLHTTP.responseText) != "") {
            var StrPriData = ObjPriXMLHTTP.responseText.Split('~');
            document.getElementById('TxtEmail').value = typeof StrPriData[1] != "undefined" ? StrPriData[1] : "";
        }
        else {
            return false;
        }
Comments