Solved

Delete fields from a form

Posted on 2003-10-27
11
287 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
  • 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
Google always has something new and amazing up its sleeve, and the most current thing that they have been working on is another step in the evolution of Google Search, from machine learning to its brilliant successor, deep learning.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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