Solved

jQuery with dynamic id

Posted on 2011-09-12
2
405 Views
Last Modified: 2012-05-12
Hi,

Am trying to get the values of a <td> tag in jQuery function which am not getting it.  Here is the code.  The line which is bold and italic is the point where i need the value of tag <td>:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<%@page import="java.util.List"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Tremor VTQ Page</title>
<style type="text/css">
.even {
      background-color: silver;
}
</style>
<style type="text/css" media="screen">
    .jqplot-axis {
      font-size: 0.85em;
    }
    .jqplot-title {
      font-size: 1.1em;
    }
</style>
<link rel="stylesheet" type="text/css" href="/js/jquery.jqplot.css" />
<script language="javascript" type="text/javascript" src="<c:url value="/js/jquery.js"/>"></script>
<script language="javascript" type="text/javascript" src="<c:url value="/js/jquery.jqplot.js"/>"></script>
<script language="javascript" type="text/javascript" src="<c:url value="/js/jqplot.canvasTextRenderer.min.js"/>"></script>
<script language="javascript" type="text/javascript" src="<c:url value="/js/jqplot.canvasAxisLabelRenderer.min.js"/>"></script>
<script language="javascript" type="text/javascript">
$(document).ready(
            function (){
                  alert('Inside JS.');
                  $.jqplot.config.enablePlugins = true;
                  var nocArr = [];
                  var times = [];                                    
                  for (var i=0;  i<20; i++) {
                        alert(i+' -- '+$("#numOccurences"+i).data());
                      nocArr.push([i, $("div#numOccurences"+i)]);
                    }
                    var plot1 = $.jqplot("chart1", [[nocArr]]);
            });
</script>
</head>
<body>
<div id="mainDiv" title="Main Block" style="border: 1px;border-color: black; background-color: white">
      <table id="mainTab" style="border: thick; border-color: black" cellpadding="5" rules="all">
            <tr id="graphrow">
                  <td>
                        <div id="dataDiv" style="margin-top:20px; margin-left:20px; width:360px; height:600px; overflow: scroll; border: medium" >
                              <c:if test="${fn:length(numOccurrences) > 0}">
                                    <table id = "tableGraph" cellpadding="5">
                                          <thead id="tableheader" valign="top">
                                                <tr class="even">
                                                      <th>Number of Occurrences </th>
                                                      <th>Generated Time </th>
                                                </tr>
                                          </thead>
                                          
                                          <c:forEach items="${numOccurrences}" varStatus="status">
                                          <tr>
                                                <td id="numOccurences${status.index}">${numOccurrences[status.index]}</td>
                                                <td id="timeInterval${status.index}">${timeInterval[status.index]}</td>
                                          </tr>
                                          </c:forEach>
                                    </table>
                              </c:if>
                        </div>
                  </td>
                  <td id ="count" style="width: 1px" title="${fn:length(numOccurrences)}"/>
                  <td>
                        <div id="chart1" style="margin-top:2px; margin-left:20px; width:360px; height:300px;"></div>
                  </td>
            </tr>
      </table>
</div>
</body>
</html>
0
Comment
Question by:lakkarajumurali
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36523468
what about :

$(document).ready(
            function (){
                  alert('Inside JS.');
                  $.jqplot.config.enablePlugins = true;
                  var nocArr = [];
                  var times = [];
$("td:eq(0)","#tableGraph tr").each(function(i, el) {
                        alert(i+' -- '+$(this).text());
                      nocArr.push([i, $("div#numOccurences"+i)]);
})  
                       
                    var plot1 = $.jqplot("chart1", [[nocArr]]);
            });
0
 

Author Comment

by:lakkarajumurali
ID: 36523827
Great it works!! thank you.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question