Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    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.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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;

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    ... 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
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •