Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8759149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:43:43+00:00 2026-06-13T14:43:43+00:00

So just debugging someone else’s code, I’d fixed everything in Firefox and now onto

  • 0

So just debugging someone else’s code, I’d fixed everything in Firefox and now onto Chrome but when I am trying to select an option which selects all child nodes and opens their relevant graphs, I am getting a weird error:

Uncaught TypeError: Cannot call method ‘substr’ of undefined

I know the problem is (apparantly) this line:

var graph={id:seqId,entityName:flags[6].substr(1).substr(0,flags[6].length-2),entity:flags[5].substr(1).substr(0,flags[5].length-2),idCounter:flags[4],counterName:flags[3].substr(1).substr(0,flags[3].length-2),ivmanager:flags[7].substr(1).substr(0,flags[7].length-2),chart:null,pointsToShowX:null,borneInf:null,unite:"",idInstance:flagsInstance[2].substr(1).substr(0,flagsInstance[2].length-2),instanceName:flagsInstance[3].substr(1).substr(0,flagsInstance[3].length-2),listPdsNull:new Array(), countInstance:idTreeview+"_"+i, countGraph:-1};

But I have no idea why this is causing an error as everything looks correct to me?! substr is used countless times before and after the function so I have no idea why Chrome is throwing this error at me.

The full function is as below. I believe the problem is in the second part.

function loadGraphs(idTreeview,idSelectGraph)
{

    var count=0;
    var fn=$('#'+idSelectGraph)[0].attributes[1].value;
    fn=fn.substr(12).substr(0,fn.length-2);
    var flags=fn.split(new RegExp(","));
    var data=''; 

    var idInstanceTreeview = idTreeview;

if($('#counterTreeviewUL'+idInstanceTreeview).length == 0)      
{

    var fnInstance=$('#'+idSelectGraph)[0].attributes[1].value;

    var flagsInstance=fnInstance.split(new RegExp(","));

    var graph = {
            id: seqId,
            entityName: flags[6].substr(1).substr(0, flags[6].length - 2),
            entity: flags[5].substr(1).substr(0, flags[5].length - 2),
            idCounter: flags[4],
            counterName: flags[3].substr(1).substr(0, flags[3].length - 2),
            ivmanager: flags[7].substr(1).substr(0, flags[7].length - 2),
            chart: null,
            pointsToShowX: null,
            borneInf: null,
            unite: "",
            idInstance: flagsInstance[2].substr(1).substr(0, flagsInstance[2].length - 2),
            instanceName: flagsInstance[3].substr(1).substr(0, flagsInstance[3].length - 2),
            listPdsNull: new Array(),
            countInstance: idTreeview + "_" + i,
            countGraph: -1
        };

    seqId++;
    graphs[graphsLastId]=graph;
    graphsLastId++;

    }

else 
  {
    for(var i=0;i<$('#counterTreeviewUL'+idInstanceTreeview)[0].children.length;i++)
        ($('#counterTreeviewUL'+idInstanceTreeview)[0].children[i].children[0].checked)?++count:count;

    if ($('#counterTreeviewUL'+idInstanceTreeview)[0].children.length == count)
    {
        $('#'+idSelectGraph)[0].checked=true;
        $('#'+idSelectGraph)[0].indeterminate=false;
    }
    else if (count==0)
    {
        $('#'+idSelectGraph)[0].checked=true;       
        $('#'+idSelectGraph)[0].indeterminate=false;        
    }
    else
    {
        $('#'+idSelectGraph)[0].checked=true;
        $('#'+idSelectGraph)[0].indeterminate=false;
    }   
        for (var i=0;i<$('#counterTreeviewUL'+idTreeview)[0].children.length;i++)
    {   
        if (!$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].checked)
        {   
            $('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].checked=true;


       var fnInstance=$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].attributes[1].value;

       fnInstance=fnInstance.substr(15).substr(0,fnInstance.length-2);  
       var flagsInstance=fnInstance.split(new RegExp(","));


            var graph = {
                    id: seqId,
                    entityName: flags[6].substr(1).substr(0, flags[6].length - 2),
                    entity: flags[5].substr(1).substr(0, flags[5].length - 2),
                    idCounter: flags[4],
                    counterName: flags[3].substr(1).substr(0, flags[3].length - 2),
                    ivmanager: flags[7].substr(1).substr(0, flags[7].length - 2),
                    chart: null,
                    pointsToShowX: null,
                    borneInf: null,
                    unite: "",
                    idInstance: flagsInstance[2].substr(1).substr(0, flagsInstance[2].length - 2),
                    instanceName: flagsInstance[3].substr(1).substr(0, flagsInstance[3].length - 2),
                    listPdsNull: new Array(),
                    countInstance: idTreeview + "_" + i,
                    countGraph: -1
                };

            seqId++;            
            graphs[graphsLastId]=graph;             
            graphsLastId++;
        }
    }

 }
    graphsToLoad=false;
    updateAllGraphs();
    loading=false;

    if($('#counterTreeviewUL'+idInstanceTreeview).length == 0)
    {

      if($('#'+idSelectGraph)[0].checked)
        {
        countSelectedGraphs(graphsLastId, flags[5].substr(1).substr(0,flags[5].length-2), 0);
        }
      else 
        {
        countSelectedGraphs(graphsLastId, flags[5].substr(1).substr(0,flags[5].length-2), 0);
        }
    }

    else 
    {
    countSelectedGraphs(graphsLastId, flags[5].substr(1).substr(0,flags[5].length-2), 0);       
    }
}

Any insight into what’s causing this seemingly random error would be much appreciated as I can’t find much online regarding this error (the cases I’ve seen it occur are nothing like my one), thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:43:46+00:00Added an answer on June 13, 2026 at 2:43 pm

    The line

    fn=fn.substr(12).substr(0,fn.length-2);
    

    starts with making a substring, effectively stripping the first 12 letters away from the string and leaving you with “5”. (The second substr does effectively nothing in this case)

    Because fn is “5” when you assign flags then flags is also “5” which is a 1-character string and therefore flags[6] == undefined (or any index larger than 0). Just try these 3 lines in console:

    var x = "5"; 
    x[0]; // returns "5"
    x[1]; // returns undefined
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm used to debugging JavaScript in Chrome or Firefox just because their built in
I'm debugging multi-threaded code and I would just like to know if a line
I was just trying to learn and understand jQuery source code (so far with
As someone who is just starting to learn the intricacies of computer debugging, for
I am debugging a program provided to me by someone else, and do not
I am debugging an Excel 2010 plug-in, done by someone else, moving from WindowsXP
I've just started debugging my first three line long android app and I can't
i try to debug a windows gadget. Just-In-Time debugging fires up and i can
Just switched over from eclipse to vs 2008 for debugging javascript, i feel more
I just set up the Parallel Nsight debugging environment and started remote debugging my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.