Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6711951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:12:09+00:00 2026-05-26T08:12:09+00:00

Im new to HTML, Java, Javascript, JSP, and JSTL. I have a simple JSP

  • 0

Im new to HTML, Java, Javascript, JSP, and JSTL.

I have a simple JSP page using JSTL as my tag library. When I used javascript to get all the values of the a row by clicking all I can get are the values of the first row even when I click the 2nd, 3rd, or nth row. I want to get only the row I clicked.

in my javascript:

<script type="text/javascript" >
function getTblContents() {
 var pName = document.getElementById("pName").innerHTML;
 var pAddress = document.getElementById("pAddress").innerHTML;
 var pEmail = document.getElementById("pEmail").innerHTML;

 alert(pName + " " + pAddress + " " + pEmail);
}
</script>

my jstl code:

<c:forEach var="people" items="${people.data}" varStatus="status">
 <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'" onclick="getTblContents();" >
  <td id="pName" >${people.name}</td>
  <td id="pAddress" >${people.address}</td>
  <td id="pEmail" >${people.email}</td>
 </tr>
</c:forEach>

the javascript and jsp are on the same page.

Please help. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:12:09+00:00Added an answer on May 26, 2026 at 8:12 am

    Every id must be unique in html, it is restriction that html sets. So you should add some
    uniqe identifier to ids ie. people.id and past that id to javascript function.

    <script type="text/javascript" >
        function getTblContents(id) {
          var pName = document.getElementById("pName-"+id).innerHTML;
          var pAddress = document.getElementById("pAddress-"+id).innerHTML;
          var pEmail = document.getElementById("pEmail-"+id).innerHTML;
    
          alert(pName + " " + pAddress + " " + pEmail);
        }
    </script>
    
    
    <c:forEach var="people" items="${people.data}" varStatus="status">
           <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'" onclick="getTblContents('${people.id}');" >
               <td id="pName-${people.id}" >${people.name}</td>
               <td id="pAddress-${people.id}" >${people.address}</td>
               <td id="pEmail-${people.id}" >${people.email}</td>
           </tr>
    </c:forEach>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Android and Java. I have constructed an app using HTML/Javascript
I have a simple HTML page that when is load runs a javascript code
I'm using jQuery to change the HTML of a tag, and the new HTML
I have the following files: view.jsp <@ page import=... <bean:define id=mForm name=myForm type=MyForm/> <html:form
I am still new to Javascript and Servlets. I have some HTML pages containing
I'm trying to build a simple HTTP Server using Java, using java.net.ServerSocket = new
I have a java function to extract a string out of the HTML Page
I have a html page that opens a new window and loads a basic
I have noticed recently, when I apply a template to a new HTML website,
I have a button that, when pressed, will add a new HTML row. Within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.