Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Java List element is undefined inside anchor tag

There is a list defined as:

List<String> list = Arrays.asList("Abc", "Def");

The problem is inside anchor tag the list element is coming as undefined.

for (int i = 0; i < list.size(); i++) {
  <a id="<%=list.get(i)%>" href="javascript:;" onClick="openWindow(<%=list.get(i)%>);" align="left">Proceed</a>
 }

The openWindow function is defined as below:

function OpenHierarchyWindow(id) {
  alert("id value "+id.value);
}

The alert function is giving output as undefined. Why the list.get(i) is unable to fetch the data inside the anchor tag.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

here JSP scriplets inside onClick javascript function should be quoted. You can replace

onClick="openWindow(<%=list.get(i)%>);"

With

onClick="openWindow('<%=list.get(i)%>');"

Below is complete code for the same.

<%@ page import="java.util.List"%>
<%@ page import="java.util.Arrays"%>

<!DOCTYPE html>
<html>
<head>
<title>JSP Scriplets And Java Script</title>

<script type="text/javascript">
    function OpenHierarchyWindow(id) {
        alert("id value " + id);
    }
</script>

</head>
<body>

    <%
    List<String> list = Arrays.asList("Abc", "Def");
    
    for (int i = 0; i < list.size(); i++) {%>
    <a id="<%=list.get(i)%>" href="javascript:;" onClick="OpenHierarchyWindow('<%=list.get(i)%>');" align="left">Proceed</a>
    <%}%>
</body>
</html>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!