Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot access elementbyID in a javascript
    primarykey
    data
    text
    <p>I am dynamically creating hidden values on my html page in a loop, and trying to use said values to create a chart, but cannot seem to access with document.getElementByID.</p> <p>So it gets the name and a number from a servlet. The </p> <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt; &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt; &lt;html&gt; &lt;head&gt; &lt;link rel="stylesheet" type="text/css" href="buttons.css"&gt; &lt;link rel="stylesheet" type="text/css" href="${skin}.css"&gt; &lt;link rel="stylesheet" type="text/css" href="tables.css"&gt; &lt;link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'&gt; &lt;title&gt;Hello ${user}&lt;/title&gt; &lt;title&gt;Radar Chart&lt;/title&gt; &lt;script src="Chart.js"&gt;&lt;/script&gt; &lt;meta name="viewport" content="initial-scale = 1, user-scalable = no"&gt; &lt;style&gt; canvas { } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;center&gt; &lt;br&gt; &lt;div class="container"&gt; &lt;h1&gt;Number of Trades Per Stock Exchange&lt;/h1&gt; &lt;/div&gt; &lt;div id="container"&gt; &lt;table class="zebra"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope="col"&gt;Company&lt;/th&gt; &lt;th scope="col"&gt;Number of Trades Made&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;c:forEach items="${first}" varStatus="loop"&gt; &lt;tr&gt; &lt;td&gt;&lt;c:out value="${first[loop.index]}" /&gt;&lt;/td&gt; &lt;td&gt;&lt;c:out value="${price[loop.index]}" /&gt;&lt;/td&gt; &lt;input type="hidden" id="${first[loop.index]}" value="${price[loop.index]}" /&gt; &lt;/tr&gt; &lt;/c:forEach&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;br&gt; &lt;canvas id="canvas" height="450" width="450"&gt;&lt;/canvas&gt; &lt;script&gt; var pieData = [ { value : document.getElementById("London Stock Exchange"), color : "#F38630" }, { value : document.getElementById("BombayStockExchange"), color : "#E0E4CC" }, { value : document.getElementById("New York Stock Exchange"), color : "#69D2E7" } ]; var myPie = new Chart(document.getElementById("canvas").getContext( "2d")).Pie(pieData); &lt;/script&gt; &lt;br&gt; &lt;br&gt; &lt;div id="inline-link-1"&gt; &lt;a href="semanagerpanelredirect"&gt;Return to Stock Exchange Manager panel&lt;/a&gt; &lt;/div&gt; &lt;/center&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here is the source code when I load the page:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;link rel="stylesheet" type="text/css" href="buttons.css"&gt; &lt;link rel="stylesheet" type="text/css" href="blue.css"&gt; &lt;link rel="stylesheet" type="text/css" href="tables.css"&gt; &lt;link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'&gt; &lt;title&gt;Hello LondonManager&lt;/title&gt; &lt;title&gt;Radar Chart&lt;/title&gt; &lt;script src="Chart.js"&gt;&lt;/script&gt; &lt;meta name="viewport" content="initial-scale = 1, user-scalable = no"&gt; &lt;style&gt; canvas { } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;center&gt; &lt;br&gt; &lt;div class="container"&gt; &lt;h1&gt;Number of Trades Per Stock Exchange&lt;/h1&gt; &lt;/div&gt; &lt;div id="container"&gt; &lt;table class="zebra"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope="col"&gt;Company&lt;/th&gt; &lt;th scope="col"&gt;Number of Trades Made&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;London Stock Exchange&lt;/td&gt; &lt;td&gt;23&lt;/td&gt; &lt;input type="hidden" id="London Stock Exchange" value="23" /&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;BombayStockExchange&lt;/td&gt; &lt;td&gt;1&lt;/td&gt; &lt;input type="hidden" id="BombayStockExchange" value="1" /&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;New York Stock Exchange&lt;/td&gt; &lt;td&gt;9&lt;/td&gt; &lt;input type="hidden" id="New York Stock Exchange" value="9" /&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;br&gt; &lt;canvas id="canvas" height="450" width="450"&gt;&lt;/canvas&gt; &lt;script&gt; var pieData = [ { value : document.getElementById("London Stock Exchange"), color : "#F38630" }, { value : document.getElementById("BombayStockExchange"), color : "#E0E4CC" }, { value : document.getElementById("New York Stock Exchange"), color : "#69D2E7" } ]; var myPie = new Chart(document.getElementById("canvas").getContext( "2d")).Pie(pieData); &lt;/script&gt; &lt;br&gt; &lt;br&gt; &lt;div id="inline-link-1"&gt; &lt;a href="semanagerpanelredirect"&gt;Return to Stock Exchange Manager panel&lt;/a&gt; &lt;/div&gt; &lt;/center&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I can set the values but cannot get them. Any help would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    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