Error: Uncaught Typeerror: Cannot read Property 'split' of Undefined

Asked

Viewed 1,603 times

0

I have the following problem, could someone help me?

When I am on a site that runs Javascript and give a command.

The error happens in mySaved.js.196

Follows the line I click on this site Javascript claims the problem and does not perform what it would have to do:

function modifySaved(){
    var o_Element = document.getElementById(sourceElement.id);
    var applicationId = document.getElementById('applicationId').value;
    //pull report info string from the "reportInfoString" attribute
    var reportIdArrayStr = o_Element.reportInfoString;
    var reportIdArray = reportIdArrayStr.split('|'); //***NESTA LINHA O JAVASCRIPT DIZ QUE DÁ O PROBLEMA***
    var reportId = reportIdArray[0];
    var isShared = reportIdArray[1];
    var isScheduled = reportIdArray[2]; 
    var countryCode = reportIdArray[3];
    var divId = reportIdArray[4];

    modifySavedReport(reportId, isShared, isScheduled, countryCode, divId, applicationId);
}

I don’t understand much, if you can identify something wrong there.

1 answer

2

First you get an HTML element from the page:

var o_Element = document.getElementById(sourceElement.id);

Then you look for the "reportInfoString" in the found element. Since the Element type contains nothing like this name, undefined is returned.

var reportIdArrayStr = o_Element.reportInfoString;

You try to use the method split in the undefined and your Javascript gives dick:

var reportIdArray = reportIdArrayStr.split('|');

If there is an attribute called "reportInfoString" in the HTML element found, then what you wanted was this:

var reportIdArrayStr = o_Element.getAttribute('reportInfoString');

Otherwise, maybe what you want is something else, but the fact is that your o_Element.reportInfoString doesn’t do what you expect it to do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.