Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have many hyperlinks in my jsp page. Whichever link is clicked I want to store it's text in a variable. And then pass that variable.

XML
out.println("<a href=\"'+ webTempPath + '/1.mp3\">");
out.println(files);
out.println("</a>");


I have fetched the text values and made them links using the aboe code. As I have many links I want, whichever link is clicked I want that to be played.

instead of 1.mp3 that link's text to passed.Can anyone help me out.
Posted

1 solution

This is client-side matter, just use JavaScript or jQuery will do. Adapt from this sample code:
XML
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("links").on("click", "a", function(e){
        e.preventDefault(); // cancel redirecting
        var txt = $(e.target).text();
        alert(txt);
    });
});
</script>
</head>
<body>

<div class="links">

<%
out.println("<a href=\'"+ webTempPath + "/1.mp3\'>");
out.println(files);
out.println("</a>");
%>

<%-- other hyperlinks --%>

</div>

</body>
</html>

Google to find out more about jQuery.
 
Share this answer
 
Comments
Member 9671810 28-Sep-15 10:01am    
out.println(files)-- > gives output of various hyperlinks.
eg:- 1.mp3
2.mp3
3.mp3 etc.
now if I click 1.mp3 then that link value I want to store in a variable so that I can append at runtime.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900