Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to reference a particular JSON in a function call
    primarykey
    data
    text
    <p>I have two javascript routines.. the first one declares some JSON and it contains a function that takes two arguments, the first argument being the json object that needs traversing and the second argument is the tab that the rendering is done in. The second routine merely passes the name of the JSON that needs traversing and tab to render in. The code is below....</p> <pre><code>&lt;script language="JavaScript1.2" type="text/javascript"&gt; var arr = [ {"id":"10", "class":"child-of-9", "useless":"donotneed"}, {"id":"11", "class":"child-of-10", "useless":"donotneed"}]; var arrtwo = [ {"id":"12", "class":"child-of-12", "useless":"donotneed"}, {"id":"13", "class":"child-of-13", "useless":"donotneed"}]; function render_help(json,tab){ var html=''; for(var i=0;i&lt;json.length;i++){ var obj = json[i]; for(var key in obj){ var attrName = key; var attrValue = obj[key]; if (attrName == "id"){ html = html +'&lt;B&gt;'+attrValue+'&lt;/B&gt;'+'&lt;BR&gt;&lt;BR&gt;'; }else if (attrName == "class"){ html = html + attrValue + '&lt;BR&gt;&lt;BR&gt;'; } } } document.getElementById(tab).innerHTML=(html); } &lt;/script&gt; &lt;script language="JavaScript1.2" type="text/javascript"&gt; render_help(arr,"helptab"); &lt;/script&gt; </code></pre> <p>Various testing and strategically placed alert boxes indicate that the tab parameter is being passed and interpreted correctly. </p> <p>The JSON object remains elusive. For the purposes of this scripting I need the JSON "arr" to be iterated over. I feel like the answer is fairly obvious so far no luck.</p> <p>Admittedly I am new with Javascript and I am apparently missing something. Does anyone have a clue as to what I'm overlooking here?</p> <p>Happy New Year to you all! Janie</p>
    singulars
    1. This table or related slice is empty.
    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