admin管理员组文章数量:1022226
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.
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.
Share Improve this question edited Oct 30, 2012 at 7:23 Egon 4,7871 gold badge25 silver badges38 bronze badges asked Oct 30, 2012 at 6:58 StudentStudent 4,5638 gold badges29 silver badges32 bronze badges 1-
Apart from the JavaScript part: Do you really use JSP code like that? Have you ever heard of
<c:foreach/>
? I would avoid<% %>
in all my code. – Michael Piefel Commented Oct 30, 2012 at 7:20
1 Answer
Reset to default 5onclick='test("<%=logs[i].getItemName();%>");'
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.
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.
Share Improve this question edited Oct 30, 2012 at 7:23 Egon 4,7871 gold badge25 silver badges38 bronze badges asked Oct 30, 2012 at 6:58 StudentStudent 4,5638 gold badges29 silver badges32 bronze badges 1-
Apart from the JavaScript part: Do you really use JSP code like that? Have you ever heard of
<c:foreach/>
? I would avoid<% %>
in all my code. – Michael Piefel Commented Oct 30, 2012 at 7:20
1 Answer
Reset to default 5onclick='test("<%=logs[i].getItemName();%>");'
本文标签: javaPassing parameters to Javascript from jspStack Overflow
版权声明:本文标题:java - Passing parameters to Javascript from jsp - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745535304a2154933.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论