Results 1 to 5 of 5

Thread: .options.remove() only removes some items ?

  1. #1

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    .options.remove() only removes some items ?

    I have a dropdown, and I want to clear it, but this code only clears some items

    Code:
    	var i = 0; var dropDown = document.search.elements['selProductGroup'];
    	for (i = 0; i <= dropDown.length; i++) {
    		dropDown.options.remove(i);
    	}

  2. #2

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    And this doesn't make any difference...

    Code:
    	for (i = 0; i <= dropDown.length; i++) {
    		if (! ( dropDown.options[i] == null ) )
    			dropDown.options.remove(dropDown.options[i].value);
    	}

  3. #3
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345

    Re: .options.remove() only removes some items ?

    Code:
    	var i = 0; var dropDown = document.search.elements['selProductGroup'];
    	dropDown.options.length = 0;
    Should clear it?

  4. #4
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    I don't think you can set the length equal to zero, length is read only I think.

    also
    if (! ( dropDown.options[i] == null ) )
    should maybe be:
    if (dropDown.options[i] != null )
    or maybe that doesn't matter.

    if this is a dropdown as in a <select>

    then why not:
    Code:
    document.getElementById('selProductGroup').innerHTML = ""
    that's if the select is:
    <select id="selProductGroup" ... (whatever else)>
    Have I helped you? Please Rate my posts.

  5. #5
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Works for me (Internet Explorer and FireFox)

    Note: Rename to htm/html, apparently we can't upload html files.
    Attached Files Attached Files
    Last edited by TomGibbons; Apr 9th, 2004 at 09:54 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width