Delete fields from a form

mrigank used Ask the Experts™
I have a page in which there is a listing of items. To delete any item from the list I have to click on a link associated with that item.

But otherwise there is a lot of data which is transient both common to all the items and unique to each of them.

On deleting an item only that data should be removed which is unique to that item and i should see that page again. I dont know how to do it without submitting the form. Sessionattributes seem to be an idea but since the page has a lot of data it is better if that is avoided.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

>>But otherwise there is a lot of data which is transient both common to all the items and unique to each of them.On deleting an item only that data should be removed which is unique to that item and i should see that page again.

please explain a little what do u want to do?


Let me simplify things....

After deleting the item I should come back to the same page. The page contains other data as well. As i come back to that page, those data which are in text boxes, drop downs etc etc are to be prepopulated with the old values which i had selected.

How do i do that

Do u want to remove data (item)from database as well or just from the list
if yes "remove from db" then u have to submit
if no then by javascript it is very easy
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.


I have to remove data just from the list. There are other data which belong to the selected item and they are also to be removed.

Try it
function removeItems(fromCtrl) {
      var i = 0;
      var j;
      var k = 0;

      while (i < (fromCtrl.options.length - k)) {
            if (fromCtrl.options[i].selected) {
                  // remove the item
                  for (j = i; j < (fromCtrl.options.length - 1); j++) {
                        fromCtrl.options[j].text = fromCtrl.options[j+1].text;
                        fromCtrl.options[j].value = fromCtrl.options[j+1].value;
                        fromCtrl.options[j].selected = fromCtrl.options[j+1].selected;
            } else {
      for (i = 0; i < k; i++) {
            fromCtrl.options[fromCtrl.options.length - 1] = null;


<FORM NAME="main" ACTION="somewhere.asp" METHOD="GET">

Available Items:<BR>
      <OPTION VALUE="1" >Item 1</OPTION>
      <OPTION VALUE="2">Item 2</OPTION>
            <OPTION VALUE="3" >Item 3</OPTION>
      <OPTION VALUE="4">Item 4</OPTION>
      <OPTION VALUE="5" >Item 5</OPTION>
      <OPTION VALUE="6">Item 6</OPTION>

 <INPUT TYPE="BUTTON" NAME="AddBtn" VALUE="    >>    " OnClick="removeItems(this.form.AvailItems);"> <BR>



The page is something like this:

Item                Value                  Delete?
abc                  xyz                     delete(link)
123                  rst                      delete(link)

data         data             data              data      (which should remain after deleting one item)

(another table)
Item                  Value          
abc                    val1
123                    val2

I have to remove the data from thi stable to..... and continue to retain the "data" value... what i had decided was that I will make another url with the deleted item object removed... but in that case the "data" would be lost.... then i was thinking of submitting the form and redirect to this page only... again with that item removed.....

may be i was thinking of a complecated procedure.... someone suggested that i use session attributes to persist the "data" but i am not sure how good would it be in a page which contains lots of "data"


this data will remain even if u r deleting items from list by javascript as i have mentioned


I think i havent made myself clear....
The above two item - value pairs are in table form... the values which we get from their beans....

thus i dont think java script will work here


post your code, i can get your problem very well

u were saying that u don't want to submit, then u have to use javascript else u have to do submit
I don't know if you still have a problem with this. But i'm bored and maybe i can help.
I hope i understand the question.

A way you can solve it is:

Put all your data in Javascript objects and display them.
  For this you need to add constructors for your javascript objects and a function to display them (for example toHTML()).
  Put this code in your jsp page or in another file and use <script type="text/javascript" scr="yoursource.js"> </script>

  You need to create the objects. I once did it with a tag produced JavaScript, but you can do it also on the jsp page.

  For example for tag in dostartTag()

  StringBuffer output = new stringBuffer();
  output.append("<script>" + yourstuff + </script>);
  ResponseUtils.write(pageContext, output.toString());
  yourstuff here is the creation of the javascript objects. The constructors with your data.

On the place where you want to display your data call the method to display for example <script>myObjects.toHtml()</script>
The toHtml() functions also puts an id of the data in a hidden field and its status (deleted/notDeleted).

When you delete a item, hide it and put its hidden status field on deleted.

When you submit the form afterwards, you have the ids and their status. So you have all the information.

It is difficult to explain. I hope you understand what i mean.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial