Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


JSON and Prototype

Posted on 2011-02-14
Medium Priority
Last Modified: 2013-09-30
please help me use prototype to populate the 'title' div with the data inside this JSON.
    "blogPosts" : [
"postTitle" : "My Blog post title",
            "content" : "my main content",
            "image" : "th-4.jpg",

html: <div id="title"></div>

Question by:ram0nm
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34890312
document.getElementById("title").innerHTML = JSON.blogPosts.postTitle;

check this also

Author Comment

ID: 34890379
That didn't work. btw I needed this to be done using prototype not jQuery.

I think in prototype it should look like this, but it's still not working, not sure what I'm doing wrong:
$('title').innerHTML = JSON.blogPosts.postTitle; 

Open in new window

LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34890394
try it

document.getElementById("title").innerHTML = eval(JSON).blogPosts.postTitle;
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34890408
LVL 82

Accepted Solution

leakim971 earned 2000 total points
ID: 34903847
The path to get the title is :
or :

To set the innerHTML you should use update : http://www.prototypejs.org/api/element/update

Open in new window

Test page :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/prototype/"></script>
<script language="javascript">
	var myJson = {"blogPosts":[{"postTitle":"My Blog post title","content":"my main content","image":"th-4.jpg"}]};
	Event.observe(window, 'load', function() {
<div id="title"></div>

Open in new window

LVL 58

Expert Comment

ID: 39495092
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
LVL 82

Expert Comment

ID: 39495093
My last comment fully answered the question :
- use prototype instead jQuey
- show the path to the data
- working example provided

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question