You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by as as <sa...@yahoo.com> on 2004/03/03 20:55:16 UTC
Row deletion in table (jsp) using struts (and possibly javascript)
Hi,
I am basically writing a shopping cart application where I would display books collection as a table row with chekcboxagainst it and let user check a box for deletion.I aneed to capture the deleted items lis as an array (wrote a javascript function for this but as struts code gets generated on the sever, the client side javascript code for deletion fails(saying form.checkboxes.length is null)
Any tips on alternate strategies to implement the same....
Thanks in advance,
Sam.
(probably ted husted's idea of DispatchAction to get array of selectedItems...but i couldnt succeed in implemneting this due to hurdles...)
My code below...
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}
function set(target) {document.forms[0].dispatch.value=target;}
</script>
</head>
<body
<table>
<html:form action="bookDisplay" name="booksDisplayForm" type="com.shoppingcart.BooksDisplayForm">
<input type="hidden" name="finalDeleteArray"
value="return getCheckedItems();">
<input type="button" name="Delete" value= "Delete" onClick="getCheckedItems()">
<table border="1" width="100%">
<tr>
<th><input type=checkbox name="book_all" value="Check All" onClick="check(this.form.list)"></th>
<th><a href="books.jsp">Book name</a></th>
<th><a href="books.jsp">ISBN</a></th>
</tr>
<logic:iterate id="book" name="books">
<tr align="left">
<td align="center">
<input type=checkbox name="list" value="<bean:write name="book" property="id" />">
</td>
<td align="center">
<bean:write name="book" property="ISBN" />
</td>
</tr>
</logic:iterate>
</table>
</html:form>
<SCRIPT LANGUAGE="JavaScript">
function getCheckedItems()
{
var value = false;
menus = new Array;
var msg = "";
var checkBoxes = document.forms[0].elements["list"];
for(var i = 0; i < checkBoxes.length; i++)
{
if(checkBoxes[i].checked)
{
menus = menus+","+i;
value = true;
}
}
menusChopped = menus.substr(1,menus.length-1);//chop leading comma
deleteArray = new Array;
deleteArray = menusChopped.split(",");
finalDeleteArray = new Array;
for (i=0;i<deleteArray.length;i++){
finalDeleteArray[i]= deleteArray[i];
alert(finalDeleteArray[i]);
}
if(!value)
alert("Check at least one of the checkboxes, thanks.");
//this.form.action="http://myserver.com/searchById/submit.do";//fix this
//window.location.href='deleteBook.do';
return finalDeleteArray;
}
</script>
</body>
</html>
---------------------------------
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster.
Re: Row deletion in table (jsp) using struts (and possibly javascript)
Posted by as as <sa...@yahoo.com>.
I started doing with
<td align="center">
<html:checkbox name="selectedItems" property="id">
<bean:write name="book" property="ISBN" /><br>
</html:checkbox>
</td>
But I am kinda stuck as to how to retrieve the aray of selected Checkboxes
Help aprpeciate
dThanks
as as <sa...@yahoo.com> wrote:
Hi,
I am basically writing a shopping cart application where I would display books collection as a table row with chekcboxagainst it and let user check a box for deletion.I aneed to capture the deleted items lis as an array (wrote a javascript function for this but as struts code gets generated on the sever, the client side javascript code for deletion fails(saying form.checkboxes.length is null)
Any tips on alternate strategies to implement the same....
Thanks in advance,
Sam.
(probably ted husted's idea of DispatchAction to get array of selectedItems...but i couldnt succeed in implemneting this due to hurdles...)
My code below...
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}
function set(target) {document.forms[0].dispatch.value=target;}
[input]
value="return getCheckedItems();">
[input]
[input]
Book name
ISBN
[input] ">
function getCheckedItems()
{
var value = false;
menus = new Array;
var msg = "";
var checkBoxes = document.forms[0].elements["list"];
for(var i = 0; i
{
if(checkBoxes[i].checked)
{
menus = menus+","+i;
value = true;
}
}
menusChopped = menus.substr(1,menus.length-1);//chop leading comma
deleteArray = new Array;
deleteArray = menusChopped.split(",");
finalDeleteArray = new Array;
for (i=0;i
finalDeleteArray[i]= deleteArray[i];
alert(finalDeleteArray[i]);
}
if(!value)
alert("Check at least one of the checkboxes, thanks.");
//this.form.action="http://myserver.com/searchById/submit.do";//fix this
//window.location.href='deleteBook.do';
return finalDeleteArray;
}
---------------------------------
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster.
---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!