0

Alright guys, i'm trying to use the variable in the getIndividualMap function but i'm getting an undefined error. What could be the problem?

 var i; 
    for(i=0;i<=(data.length -1);i++)
    {   
    $('#ResultsId').append("<table border='1'>" + 

    "<tr>" +
    "<th>UserID</th>" +
    "<th>RUNDATE</th>" +
    "<th>NAME</th>" +
    "<th>TIME</th>" +
    "<th>DISTANCE (KM)</th>" +

    "</tr>" +
    "<tr>" + 
    "<td>" + data[i].UserID + "</td>"  + " " + 
    "<td>" + data[i].runDate + "</td>"  + " " + 
    "<td>" + data[i].firstName + "</td>"  + " " + 
    "<td>" + data[i].Time + "</td>"  + " " + 
    "<td>" + data[i].Distance + "</td>" + 
    "<td>" +"<a href='#' onclick= 'getIndividualMap(i)'>"  + data[i].UserID +"</a>" + "</td>" + 
    "</tr>" + 
    "</table>" );
    }


getIndividualMap(){
console.log(i);
}

1 Answer 1

4

Function parameter Variable missing.....

getIndividualMap(i){
console.log(i);
}

And in the below portion

"<td>" +"<a href='#' onclick= 'getIndividualMap(i)'>"  + data[i].UserID +"</a>" + "</td>" +

i is hard coded, but its a variable

It should be

"<td>" +"<a href='#' onclick= 'getIndividualMap("+ i + ")'>"  + data[i].UserID +"</a>" + "</td>" +
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.