View Full Version : Problem with deleting listbox item

05-27-2004, 05:06 AM
function delItem ()
var contSearch = 1;
var selIndex;

// check to see if there is at least one item selected
if (document.forms.frmPlant.plantList.selectedIndex == -1) {
alert("No entries selected for deletion");
return true;

// loop through all selected items and delete them
while (contSearch > 0) {
selIndex = document.forms.frmPlant.plantList.selectedIndex;
if (selIndex >= 0) {
document.forms.frmPlant.plantList.options[selIndex] = null;
contSearch = 0;

return true;

I am having problems with deleting the whole row of the listbox. It seems to delete the current text but not the item itself (when you add a new item, there is a gap where the one you deleted is.

The page is located at www.killuke.com.au/?page=order_form

other feedback on the order form would be good also (besides the fact of using db for listbox items :p).

I was wondering if there is a way to hide the send order button (and or the enter key) until all criteria is met so they dont send a blank order. (order is sent via php mail function)

if you need any mre code just ask.


05-27-2004, 06:46 AM
The problem seems to be in the btnAdd() function.
Change this:

document.forms.frmPlant.plantList.options[numItems++] = addOption;


document.forms.frmPlant.plantList.options[document.forms.frmPlant.plantList.options.length] = addOption;

You should store the form reference to a variable to optimize your code.

var f=document.forms.frmPlant;
var Quantity = f.plantQuantity.value;
var Size = f.plantSize.value;
var Plant = f.plantName.value;
f.plantList.options[f.plantList.options.length] = addOption;

05-27-2004, 09:26 AM
... and a good practice is to use this and this.form as refference parameters in functions called by event handlers.

Thus, using

<select onchange="somefunction(this.form,this)>

in code you will have, let's say


in which f and s will succesfuly substitute


as objects

05-27-2004, 05:44 PM
Thanks heaps for your quick responces. The code modification worked great and i cant understand why i wouldnt have used it in the first place.

Thanks also for ur sugestions. Will modify script straight away