Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing Json values between javascript functions
    primarykey
    data
    text
    <p>I am getting in JSon data , I am using dom to display the data , I want to embed a link to each search result displayed which when clicked passes that instance of data to another block and display that result</p> <p>my HTML code is </p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;div id:block 1 &gt; &lt;div id:block 2&gt; &lt;div id:block 3&gt; &lt;/body&gt; </code></pre> <p>My Javascript function is </p> <pre><code>function addBooks(data) { // the data is a list of JSON objects var listdiv = document.createElement('li'); listdiv.setAttribute('id', 'gBookListDiv'); listdiv.innerHTML = ("Books Found:"); parent.appendChild(listdiv); for(i = 0; i &lt; data.length; i++) { //create each list item var listItem = document.createElement('li'); var link = document.createElement('a'); listItem.setAttribute('id', 'gBookListItem'); parent.appendChild(listItem); link.setAttribute('href', '#'); link.setAttribute('onclick', 'displayBook(data[i])'); listItem.appendChild(link); } } function displayBook(bookData) { alert(bookData.title); if(document.getElementById("block2").style.display == "block") { document.getElementById("block2").style.display = "none"; document.getElementById("block3").style.display = "block"; } var headerTitle = document.getElementById('book-profile-title-header'); headerTitle.innerHTML = bookData.title; var title = document.getElementById('book-profile-pic'); headerTitle.innerHTML = bookData.title; } </code></pre> <p>For some reason , I am not able to pass the instance of data to the displayBook function.</p> <p>this is the error I get on chrome</p> <blockquote> <p>Uncaught ReferenceError: data is not defined </p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload