Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-27-2004, 05:06 AM   PM User | #1
Serex
Regular Coder

 
Join Date: Mar 2004
Location: Australia
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Serex is an unknown quantity at this point
Problem with deleting listbox item

Code:
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;
                 }
              else 
                 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 ).

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.

thanks

Last edited by Serex; 05-27-2004 at 05:09 AM..
Serex is offline   Reply With Quote
Old 05-27-2004, 06:46 AM   PM User | #2
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
The problem seems to be in the btnAdd() function.
Change this:

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

to:

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;
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 05-27-2004, 09:26 AM   PM User | #3
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
... 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

somefunction(f,s){
...
}

in which f and s will succesfuly substitute

document.formaname
and
document.formaname.selectname

as objects
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 05-27-2004, 05:44 PM   PM User | #4
Serex
Regular Coder

 
Join Date: Mar 2004
Location: Australia
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Serex is an unknown quantity at this point
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
Serex is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:25 AM.


Advertisement
Log in to turn off these ads.