Solved

Delete fields from a form

Posted on 2003-10-27
11
285 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
Comment Utility
>>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
Comment Utility
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
Comment Utility
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
 
LVL 5

Author Comment

by:mrigank
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Author Comment

by:mrigank
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
post your code, i can get your problem very well
0
 
LVL 2

Expert Comment

by:Karaa
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now