I have a JSP page that looks like this:
I added a button Copy URL
and it's self explanatory that when I click the button, I need to copy the unique URL for that particular link itself.
This is how my front end looks:
<%
//need to input logic to populate data on each row
int counter=0;
String[] split = request.getParameter("nodeID").split(",",0);
for(int i=0;i<split.length;i++){
long file=Long.parseLong(split[i]);
List files = fileFacade.list_items(file);
for (Iterator rstltr = files.iterator(); rstltr.hasNext();) {
Fmedia fv = (Fmedia) rstltr.next();
Node nd = nodeFacade.get(fv.getNodeid(), false);
// Fmedia fm = fileFacade.get_file(fv.getNodeid());
int count = 0;
count++;
long fileid= nd.getNodeid();
%>
<tbody>
<tr>
<td width="5%">
<!--Display Checkbox -->
<input type="checkbox" name="name1" />
</td>
<td>
<!--Display No -->
<% counter=counter+1;
out.print(counter);
%>
</td>
<td width="28%">
<!-- Display Filename -->
<%=nd.getNodedesc()%>
</td>
<td width="100%">
<!-- Display URL -->
<%="http://localhost:8080/repository/file/view/viewPDF.jsp?count=1&f0="+nd.getNodeid()%>
<%
fileFacade.insert_url(nd.getNodeid(),"http://localhost:8080/repository/file/view/viewPDF.jsp?count=1&f0="+nd.getNodeid());
%>
</td>
<td>
<!-- Display EDIT/DEL -->
</td>
<td> <!-- Display COPY feature -->
<input type="button" value="Copy URL" onclick="msg()">
<script>
function msg() {
alert("Hello world!");
}
</script>
</td>
</tr>
</tbody>
<%}}
%>
I need a way that each button is independent of each row and a javascript function to be able to copy the link after selecting the checkbox.
I am not too sure how to proceed from here.
Can anyone suggest a good approach?
EDIT:
Javascript function:
<input type="button" value="Copy URL" onclick="getURL()">
<script>
function getURL() {
var copyText = "http://localhost:8080/repository/file/view/viewPDF.jsp?count=1&f0="+<%nd.getNodeid();%>
var el = document.createElement('textarea');
el.value = copyText;
el.setAttribute('readonly', '');
el.style = {
position: 'absolute',
left: '-9999px'
};
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
</script>
</td>