Results 1 to 2 of 2
- 09-22-2010, 01:57 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 3
- Rep Power
- 0
using javascript variable for jsp
hello all, my code is like this:
<%
ArrayList<Item> itemList = new ArrayList<Item>();
itemList = projr.getObjects(projectID);
if (itemList.size() != 0) {
%>
<script type="text/javascript">
window.onload = function() {
for(var i = 0;i < <%=itemList.size()%>;i++){
var azimuth=0;
azimuth = <%=itemList.get(i).getAzimuth()%>;
</script>
<%
}
%>
basically as you can see, due to certain reasons, i need to do the for loop within javascript. However, I cannot use the variable 'i' declared in javascript within the jsp<%=%> tag. Hence, I was wondering if there could be any work arounds.
I've tried to store 'i' as a cookie and try to retrieve it in the jsp by doing smth like:
azimuth = <%=itemList.get(Integer.parseInt((request.getCooki es())[0].getValue())).getAzimuth()%>;
However, sadly this doesn't work. Also, I've thought of using hidden input fields to store 'i' but I don't think it would work as even if a did a request.getParameter(input name), i would not get anything as I have not submitted anything. Am I correct to say that?
I would appreciate if any of you kind souls could help me out here =]
- 09-22-2010, 03:12 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
You're making a common mistake here.
The JSP code itself is run on the server. This creates the page you see on the client (ie browser), which is where the javascript will run. You cannot run Java code in you Javascript code (which seems to be what you;re attempting).
You probably need to describe what it is you're trying to achieve.
Similar Threads
-
How do I substitute any variable for a hardcoded variable
By Weazel Boy in forum New To JavaReplies: 11Last Post: 07-07-2010, 06:02 AM -
how to access JSP variable in javascript
By sauravsinha in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-31-2010, 04:41 PM -
javascript variable
By raghu9198 in forum New To JavaReplies: 3Last Post: 01-29-2009, 07:42 AM -
javascript
By fiero in forum New To JavaReplies: 1Last Post: 09-22-2008, 01:45 PM -
Jsp and javascript
By Ed in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 07-04-2007, 04:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks