Solved

Delete fields from a form

Posted on 2003-10-27
11
288 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fisheye tool 2 116
constructor overloading 2 86
own marker interface 1 57
how to add new optional parameter to JSP 1 49
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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