473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Deleting Items

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

function lstCarts_ondblclick()
{
index = NewProgram.lstCarts.selectedIndex;
if (index != -1)
{
vID = NewProgram.lstCarts.options[index].value;
vText = NewProgram.lstCarts.options[index].text;
NewProgram.lstNewCarts.options[NewProgram.lstNewCarts.length] = new
Option(vText);
NewProgram.lstNewCarts.options[NewProgram.lstNewCarts.length -
1].value = vID;
eval("NewProgram.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_ondblclick()
{
index = NewProgram.lstNewCarts.selectedIndex;
if (index != -1)
{
vID = NewProgram.lstNewCarts.options[index].value;
vText = NewProgram.lstNewCarts.options[index].text;
eval("NewProgram.Item" + vID + ".value = -1");
}
}

Oct 21 '05 #1
3 1482
bb*****@synergyhq.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_ondblclick()
{
index = NewProgram.lstCarts.selectedIndex;
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.lstCarts.selectedIndex;
if (index != -1)
{
vID = NewProgram.lstCarts.options[index].value;
vText = NewProgram.lstCarts.options[index].text;
NewProgram.lstNewCarts.options[NewProgram.lstNewCarts.length] = new
Option(vText);
NewProgram.lstNewCarts.options[NewProgram.lstNewCarts.length -
1].value = vID;
eval("NewProgram.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_ondblclick()
{
var oForm = document.forms.NewProgram; // reference tot the form
var oSel = oForm.lstCarts; // reference to the select
var nSel = oForm.lstNewCarts; // reference to 'new' select
var idx = oSel.selectedIndex; // 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.length] = 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_ondblclick()
{
index = NewProgram.lstNewCarts.selectedIndex;


var sel = document.forms.NewProgram.1stNewCarts;
sel.removeChild(sel.options[sel.options.selectedIndex]);
}

Here's a full working example using onchange, it will not delete the
default 1st option in the lstNewCart:
<form name="NewProgram" action="">
<select name="lstCarts" onchange="cartOnchange();">
<option value="value1">text1</option>
<option value="value2">text2</option>
<option value="value3">text3</option>
</select>
<select name="lstNewCarts" onchange="cartNewOnchange();">
<option>default 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.lstNewCarts; // reference to 'new' select
var idx = oSel.selectedIndex; // 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.length] =
new Option(vText, vID, false, true);
}

function cartNewOnchange()
{
var sel = document.forms.NewProgram.lstNewCarts;
if (sel.options.selectedIndex) {
sel.removeChild(sel.options[sel.options.selectedIndex]);
}
}
</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="listCombineCart" name="listCombineCart"
language="javascript" width="250">
<option>default 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*****@synergyhq.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.com, 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="listCombineCart" name="listCombineCart"
language="javascript" width="250">
select lists do not have a language attribute.
<option>default 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.javascript 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
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...
18
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 ...
2
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...
1
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...
1
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...
1
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...
10
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:...
0
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...
8
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;...
9
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. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...

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.