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 8650203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:45:39+00:00 2026-06-12T13:45:39+00:00

In my JSP page ,i want to dynamically create a label, which is inside

  • 0

In my JSP page ,i want to dynamically create a label, which is inside a achor tag. when i clik another anchor tag , i want to get corresponding label text using javascript or jquery.

This is my JSP page code.

<body>
    <%
        for (int i = 0; i < sam.groupName.length; i++) {

            out.print("<a href='#'>");
            out.print("<img src='twoMen.jpg'/>");
            out.print("<label for='groupsId' id='labelId"+i+"'>"+ sam.groupName[i] + "</label>");
            out.print("</a>");

            out.print("<a href='javascript:void(0);' onclick='validation(this,"+i+");'>Edit</a>");

        }
    %>
</body>

Javascript code:

function validation(anchor,i) {
        alert("Label value="+????);
    }
  • 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-06-12T13:45:40+00:00Added an answer on June 12, 2026 at 1:45 pm

    Quick answer:

    function validation(anchor,i) {
        var value = $("#labelId"+i).text();
        alert("Label value= "+ value);
    }
    

    Just use the ID of the label you have, then get the text from it.

    .text() will return to you the TEXT that is in the tag. Not if that text is contained within another nested tag. If that is the case, use .html() or specify your jQuery selector.

    UPDATE

    I also thought of another solution, this one will be simpler I think:

    <body>
    <%
        for (int i = 0; i < sam.groupName.length; i++) {
    
            out.print("<a href='#'>");
            out.print("<img src='twoMen.jpg'/>");
            out.print("<label for='groupsId' id='labelId"+i+"'>"+ sam.groupName[i] + "</label>");
            out.print("</a>");
    
            out.print("<a href='javascript:void(0);' onclick='validation(this,'"+sam.groupName[i]+"');'>Edit</a>");
    
        }
        %>
    </body>
    

    then you can use the validation function as follows:

    function validation(anchor,value) {
        alert("Label value="+ value);
    }
    

    This does the same, but it passes the value you need instead of the index pointing to the value you need. This works UNLESS you need the i index for anything else later on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A jsp page in which dynamic datas are there. I want to get the
I want to create a Thread safe JSP page. It is possible in Servlet
i have put fckeditor in jsp page. I want to get the value whatever
I want to add a file uploader to my JSP page. Inside the JSP,
I am generating dynamic page using JSP, I want to save this dynamically generated
I want to create a table containing three string columns: The JSP page Part
I want my JSP page to include another page based on a value in
I want to add textbox dynamically in jsp page on Add Row button click.
I am using azax to dynamically change the jsp page and I want to
Inside my jsp page, I have a string I want to show, but it

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.