473,785 Members | 2,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting Items

I add items to a list of ids within a <TD> named lstCarts using the
following code:

function lstCarts_ondblc lick()
{
index = NewProgram.lstC arts.selectedIn dex;
if (index != -1)
{
vID = NewProgram.lstC arts.options[index].value;
vText = NewProgram.lstC arts.options[index].text;
NewProgram.lstN ewCarts.options[NewProgram.lstN ewCarts.length] = new
Option(vText);
NewProgram.lstN ewCarts.options[NewProgram.lstN ewCarts.length -
1].value = vID;
eval("NewProgra m.Item" + vID + ".value = " + vID);
}
}

This works fine. When I highlight an item in lstNewCarts and click on
a button to delete these items from the list the following code is
executed. This doesn't work becauset the selected item does not
disappear from the list.

function lstNewCarts_ond blclick()
{
index = NewProgram.lstN ewCarts.selecte dIndex;
if (index != -1)
{
vID = NewProgram.lstN ewCarts.options[index].value;
vText = NewProgram.lstN ewCarts.options[index].text;
eval("NewProgra m.Item" + vID + ".value = -1");
}
}

Oct 21 '05 #1
3 1509
bb*****@synergy hq.com wrote:
I add items to a list of ids within a <TD> named lstCarts using the
following code:
Is 'lstCarts' the name or the id? There is no name attribute for a td
element. But it appears from your code below that '1stCarts' is a
select element.

For maintainability , 'lstCarts' is not a great choice of name because of
the leading characters - lower case letter 'l' is easily confused with
the numeral '1', particularly when followed by 'st'. Perhaps
'listCart' would be clearer, it adds but one character.

function lstCarts_ondblc lick()
{
index = NewProgram.lstC arts.selectedIn dex;
What is 'NewProgram'? I'll guess that it's a form name. In that case,
you should be using either:

document.forms['NewProgram'].elements['lstCarts'].selectedIndex;

or a the shorter:

document.forms. NewProgram.lstC arts.selectedIn dex;
if (index != -1)
{
vID = NewProgram.lstC arts.options[index].value;
vText = NewProgram.lstC arts.options[index].text;
NewProgram.lstN ewCarts.options[NewProgram.lstN ewCarts.length] = new
Option(vText);
NewProgram.lstN ewCarts.options[NewProgram.lstN ewCarts.length -
1].value = vID;
eval("NewProgra m.Item" + vID + ".value = " + vID);
}
}
Whenever you are tempted to use eval, don't. It is almost never needed.

If the intention is to create a new option in another select named
'lstNewCart' using values from chosen select, then:

function lstCarts_ondblc lick()
{
var oForm = document.forms. NewProgram; // reference tot the form
var oSel = oForm.lstCarts; // reference to the select
var nSel = oForm.lstNewCar ts; // reference to 'new' select
var idx = oSel.selectedIn dex; // selected option index
var vID = oSel[idx].value; // value of selected option
var vText = oSel[idx].text; // text of selected option

// Add the new option
nSel.options[nSel.options.le ngth] = new Option(vText, vID, true);
}

You should look at passing 'this' from the function call so that you
don't have to hard-code so many references.

This works fine. When I highlight an item in lstNewCarts and click on
a button to delete these items from the list the following code is
executed. This doesn't work becauset the selected item does not
disappear from the list.
If you want the option to be removed, then you have to delete it.
Setting its value to -1 does not delete it. You must always have at
least one option in the select, or you'll have invalid HTML.

function lstNewCarts_ond blclick()
{
index = NewProgram.lstN ewCarts.selecte dIndex;


var sel = document.forms. NewProgram.1stN ewCarts;
sel.removeChild (sel.options[sel.options.sel ectedIndex]);
}

Here's a full working example using onchange, it will not delete the
default 1st option in the lstNewCart:
<form name="NewProgra m" action="">
<select name="lstCarts" onchange="cartO nchange();">
<option value="value1"> text1</option>
<option value="value2"> text2</option>
<option value="value3"> text3</option>
</select>
<select name="lstNewCar ts" onchange="cartN ewOnchange();">
<option>defau lt empty option</option>
</select>
</form>

<script type="text/javascript">
function cartOnchange()
{
var oForm = document.forms. NewProgram; // reference tot the form
var oSel = oForm.lstCarts; // reference to the select
var nSel = oForm.lstNewCar ts; // reference to 'new' select
var idx = oSel.selectedIn dex; // selected option index
var vID = oSel[idx].value; // value of selected option
var vText = oSel[idx].text; // text of selected option

// Add the new option - wrapped for posting
nSel.options[nSel.options.le ngth] =
new Option(vText, vID, false, true);
}

function cartNewOnchange ()
{
var sel = document.forms. NewProgram.lstN ewCarts;
if (sel.options.se lectedIndex) {
sel.removeChild (sel.options[sel.options.sel ectedIndex]);
}
}
</script>
[...]
--
Rob
Oct 21 '05 #2
This works great. Now my issue is more with VBScript since this is
what is processing the Postback on the server. I have changed the name
of lstNewCarts to listCombineCart . The following is the HTML.

<td align="center">
Carts to be Combined
<select size="10" id="listCombine Cart" name="listCombi neCart"
language="javas cript" width="250">
<option>defau lt empty option</option>
</select>
</td>

Now how do I access only this item list in VBScript? Probably not the
best place to ask this question.

Oct 22 '05 #3
bb*****@synergy hq.com said the following on 10/21/2005 8:29 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.c om, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
This works great. Now my issue is more with VBScript since this is
what is processing the Postback on the server. I have changed the name
of lstNewCarts to listCombineCart . The following is the HTML.

<td align="center">
Carts to be Combined
<select size="10" id="listCombine Cart" name="listCombi neCart"
language="javas cript" width="250">
select lists do not have a language attribute.
<option>defau lt empty option</option>
</select>
</td>

Now how do I access only this item list in VBScript? Probably not the
best place to ask this question.


No, it's not. You might try a microsoft.* group for server side VBScript.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1488
by: Amit Kela | last post by:
I am using ASP with SQL for my database. The problem I have is that even after I have ordered certain items from the shopping cart table on the webpage, I cannot remove them - that is the entire list shows up the next time the table is opened. is there any way I can delete the items once ordered so as to not let them show in my table??
18
2482
by: Dan | last post by:
hello, I would to know if it is possible to delete an instance in an array, The following does not allow me to do a delete. I am trying to find and delete the duplicate in an array, thanks for ( j =0; j<MAX ; j++) { for ( i =0; i<MAX ; i++)
2
1780
by: KraftDiner | last post by:
I have a list, and within it, objects are marked for deletion. However when I iterate through the list to remove objects not all the marked objects are deleted.. here is a code portion: i = 0 for obj in self.objList: if obj.mouseHit: print 'delete + ' + `i` self.objList.pop(i)
1
7902
by: jez123456 | last post by:
Hi, I have a windows form with a listbox control. My code all works correctly when deleting an item from the listbox except the last item. I get the following message when trying to delete the last item:- Specified argument was out of the range of valid values. Parameter name: '64' is not a valid value for 'Value'. The 64 reduces depending on how many listbox items are displayed.
1
4290
by: Crash | last post by:
Windows XP SP2 C# .NET v1.1 Outlook 2003 {via Office 11.0 PIA} I'm manipulating Outlook's calendar via OLE automation from my C# application. I would like to iterate through the calendar items collection and delete appointments from the items collection based on some business rules. However after I delete/remove items I am getting "index out of range" and/or "object has been moved or deleted" errors. Also, sometimes it seems that the...
1
1706
by: Tim | last post by:
Hi, I'm very new to .NET and am programming in C#. I have a web application where i have two list boxes. Its kind of like a shopping card where you can add items from one 'locations' list box to the 'locations selected' (cart) listbox. I have a hirarchy of locations - main locations and sub locations. main locations being the parent locations, and the sub locations being the child locations. I want to be able to check to see if the...
10
4404
by: A_PK | last post by:
I am writing mobile application using Vb.net when i click the last row of list view, and try to delete it.... will promtpy the following message "Additional information: ArgumentOutOfRangeException" what does that mean ? I can delete any row without problem but except last row only....
0
1538
by: steven.shannon | last post by:
Hello, I'm writing an app that involves deleting all the items in a specified Outlook folder regardless of item type (i.e. Contacts, Tasks, etc.). This code was ported from VBA where it worked okay, but now in .NET it is exceedingly too slow when attempting to delete large collections (roughly 10,000). It is on the order of 10 items deleted every 30 seconds. My function is as follows: Private Sub DeleteAllEntries()
8
1953
by: Christian Bruckhoff | last post by:
Hi. I got a problem with deleting items of a vector. I did it like this: void THIS::bashDelPerson() { cout << "Bitte Suchstring eingeben: "; char search; cin >search; vector<Person>::iterator iter; iter = persons.begin();
9
2441
by: Rhamphoryncus | last post by:
The problems of this are well known, and a suggestion for making this easier was recently posted on python-dev. However, I believe this can be done just as well without a change to the language. What's more, most of the suggested methods (in my search results as well as the suggestion itself) do not scale well, which my approach would solve. My approach is to make a set of indexes to removed while iterating, then use a list...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10327
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.