Solved

Delete fields from a form

Posted on 2003-10-27
11
290 Views
Last Modified: 2010-04-01
Hi,
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.

Thanks
Mrigank
0
Comment
Question by:mrigank
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 2

Expert Comment

by:Karaa
ID: 9625717
>>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?
0
 
LVL 5

Author Comment

by:mrigank
ID: 9625747
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
0
 
LVL 2

Expert Comment

by:Karaa
ID: 9625775
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:mrigank
ID: 9625804
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.

0
 
LVL 2

Assisted Solution

by:Karaa
Karaa earned 50 total points
ID: 9625899
Try it
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
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;
                  }
                  k++;
            } else {
                  i++;
            }
      }
      for (i = 0; i < k; i++) {
            fromCtrl.options[fromCtrl.options.length - 1] = null;
      }
}
//-->
</SCRIPT>

</HEAD>

<FORM NAME="main" ACTION="somewhere.asp" METHOD="GET">
<INPUT TYPE="HIDDEN" NAME="Avail">
<INPUT TYPE="HIDDEN" NAME="Sel">

<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD VALIGN="TOP">
Available Items:<BR>
<SELECT MULTIPLE NAME="AvailItems" SIZE="5">
      <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>

</SELECT>
</TD>
<TD ALIGN="CENTER">
 <INPUT TYPE="BUTTON" NAME="AddBtn" VALUE="    >>    " OnClick="removeItems(this.form.AvailItems);"> <BR>
<BR>
</FORM>

</BODY>
</HTML>
0
 
LVL 5

Author Comment

by:mrigank
ID: 9625975
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"

Regards
0
 
LVL 2

Expert Comment

by:Karaa
ID: 9626030
this data will remain even if u r deleting items from list by javascript as i have mentioned
0
 
LVL 5

Author Comment

by:mrigank
ID: 9626091
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

regards
0
 
LVL 2

Expert Comment

by:Karaa
ID: 9626092
post your code, i can get your problem very well
0
 
LVL 2

Expert Comment

by:Karaa
ID: 9626341
u were saying that u don't want to submit, then u have to use javascript else u have to do submit
0
 
LVL 2

Accepted Solution

by:
DidierD earned 50 total points
ID: 9771052
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is a lot to be said for protecting yourself and your accounts with 2 factor authentication.  I found to my own chagrin, that there is a big downside as well.
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question