0

I have some files up on Parse.com and want to pull them down using JSON. After I pull down the json data I wish to display this on a HTML page. One of the elements I am pulling down is nested and contains the objectID of a element I wish to make a further call to.

Here is the line I am stuck with:

        document.getElementById("subjectName").innerHTML=subject.exam.objectId;

This is setting a HTML tag to undefined. If I have a similar structure such as:

        document.getElementById("subjectName").innerHTML=subject.exam.className;

it will set the element as expected. The JSON data I am pulling down is as follows

{
"exam": {
    "__type": "Pointer",
    "className": "exam",
    "objectId": "UP7CeBZNz8"
},
"name": "Computer Architecture",
"objectId": "Pf1tKLYzjz",
"createdAt": "2014-04-24T09:22:22.732Z",
"updatedAt": "2014-04-29T16:21:40.855Z"
}

If anyone can help with this it would be much appreciated!

2
  • You're setting both to document.getElementById("subjectName"). Is that expected? Commented Apr 29, 2014 at 21:05
  • 1
    What do you see logged if you add console.log(subject) at that point in your code? Commented Apr 29, 2014 at 21:05

1 Answer 1

1

The problem might be because you're setting it to the same element.

if you have used

document.getElementById("subjectName").innerHTML

in both the assignments, it will not work. this works:

document.getElementById("objectId").innerHTML=subject.exam.objectId;
document.getElementById("subjectName").innerHTML=subject.exam.className;

Fiddle here

Sign up to request clarification or add additional context in comments.

1 Comment

That was not the issue. The element was under subject.exam.id rather than .objectId; I dont know why the JSON printout I have used objectId but it is working now :)

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.