How do i view a Google chart in a JSP page? [duplicate] - javascript

This question already has answers here:
Access Java / Servlet / JSP / JSTL / EL variables in JavaScript
(5 answers)
Closed 6 years ago.
I am trying to convert my List of Doubles in EL to a Array in JavaScript for use further on with Google Charts.
But i am stuck here in the snippet it sees the var prices as an array of Characters.
<head>
${requestScope.prices} <!-- gives [130.98, 130.84, 133.23, 130.32] -->
<p id="demo"></p>
<script type='text/javascript'>
var prices = "${requestScope.prices}";
document.getElementById("demo").innerHTML = prices[2]; //Gives 3
</script>
</head>

You can try it using JSTL. Firstly, fill js array this like and access it.
var prices = [
<c:forEach var="price" items="${prices}">
<c:out value="${price}" />,
</c:forEach>
];
document.getElementById("demo").innerHTML = prices[2];

Related

Datatype .innerHTML [duplicate]

This question already has answers here:
How do I get the value of text input field using JavaScript?
(16 answers)
Closed 2 years ago.
I´m getting a NaN out of this script, is it a data type problem and how do i solve it?
<script>
function calc(){
var profile = document.getElementById("profil");
var hours = document.getElementById("hour");
document.getElementById("result").innerHTML=profile*hours;
}
</script>
Present the result like this
<button onclick="calc()">Calc</button><br>
<p id="result"></p>
You have to get the value from the element.
var profile = document.getElementById("profil").value;
With .getElementById you get a DOM Element.
Supposing "profil" and "hour" are input elements, you want to obtain their values:
<script>
function calc(){
var profile = document.getElementById("profil").value;
var hours = document.getElementById("hour").value;
document.getElementById("result").innerHTML=profile*hours;
}
</script>

How can I use js var in html? [duplicate]

This question already has answers here:
How to display JavaScript variables in a HTML page without document.write
(9 answers)
Closed 4 years ago.
I'm actually trying to use a js var in my html code like this :
In javascript code :
var test = 'This is a test';
And in the html :
<p>display var test here</p>
How can I display the value of my js var in html like this ?
HTML:
<p id="paragraph"></p>
JavaScript:
var test = 'This is a test';
document.getElementById('paragraph').innerHTML = test;

creating an array in jsp from list of objects [duplicate]

This question already has answers here:
Access Java / Servlet / JSP / JSTL / EL variables in JavaScript
(5 answers)
Closed 6 years ago.
I am trying to build an array of DemoNames.name attribute, dynamically in jsp, how can i create an array and then pass to my js file for further validation?
<c:forEach items="${demoNames}" var="DemoNames">
${DemoNames.name}
</c:forEach>
You'll want to make this code declaration somewhere in the html after the js file is declared.
<script>
var nameArray = [];
<c:forEach items="${demoNames}" var="DemoNames">
nameArray.push("${DemoNames.name}");
</c:forEach>
yourJSFileFunction( nameArray );
</script>
If you viewed source on this I believe you would have a push line for each of the names.

How to retrieve setAttribute from servlet into JavaScript [duplicate]

This question already has answers here:
Access Java / Servlet / JSP / JSTL / EL variables in JavaScript
(5 answers)
Closed 6 years ago.
I'm trying to retrieve the value of my setAttribute into my javascript code but I get a syntax error when I run the page.
Here is the code of my setAttribute in my servlet:
request.setAttribute("codeIGA", codeIGA); //a string is being passed here
Here is the code of my JS:
$(document).ready(
function () {
var count = 0;
var lastCodeIGA = ${sessionScope.codeIGA}; // syntax error here
console.log(lastCodeIGA);
.
.
.
etc
How can I retrieve the value from my servlet and input it into my JS?
You can use following to retrieve the required value.
var lastCodeIGA = '${codeIGA}';
Try with scriptlet.
var test = <%=request.getAttribute("codeIGA");
Or
var lastCodeIGA = '${codeIGA}';

How to get the sheet object in the sheet properties? [duplicate]

This question already has answers here:
How can a JavaScript object refer to values in itself? [duplicate]
(8 answers)
Closed 9 years ago.
How to get the form object?
I use this.box meaning sheet.box here, but the script produces an error. How do I get the sheet object in the sheet properties?
<div class="box">
<form action=""></form>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
var sheet={
box: $('.box'),
form: this.box.find('form') // TypeError: this.box is undefined
}
</script>
I guess what you need is a function:
form: function() {return this.box.find('form');}
Otherwise, you should be more specific.
Old versions of Firefox (I tried Firefox 4 which warns but still accepts it) actually allowed you to do this:
var sheet = {
box: #1= $('.box'),
form: #1#.find('form')
}

Categories

Resources