简体   繁体   中英

Passing parameters to Javascript from jsp

I have a javascript function that I need to call on click of the delete button -

JavaScript:

function test(var1) {
    alert(var1);
}

JSP code ( logs is an ArrayList of length 10):

<table>
<%
for(int i=0; i<len; i++)
{
%>
    <tr>
    <td><%out.println(logs[i].getItemName());%></td>
    <td><%out.println(logs[i].getItemDesc()); %></td>
    <td> <input class="submit" type="submit" value="Delete" onclick="test(<%logs[i].getItemName();%>);"/></td>
    </tr>

<%
}
%>
</table>

This will print the output as -

Name1        Description1       Delete_Button

Name2        Description2       Delete_Button

.

.

Name10        Description10     Delete_Button

I am not getting how to send the correct itemname value to the JavaScript, when I click on a corresponding row's delete button. Currently I am getting the value as undefined in the JavaScript alert when I click any of the delete buttons.

onclick='test("<%=logs[i].getItemName();%>");'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM