#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    NL
    Posts
    19
    Rep Power
    0

    javascript options delete script


    Hello,

    I am working on a script that will delete all options within a selectbox based on an event. The strange thing is this script runs through the while loop but does not delete all the options..

    If i use options[i].text it will replace all text with null... but else it will delete only the even values in the options....

    very strange.. can anyone help me out here?

    PHP Code:
    var array_count=document.test.Selectbox.options.length;
    var 
    =0;
    while (
    array_count) {
     
    document.test.Selectbox.options[i] = null;
     
    i++

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    15
    In your example, the variable array_count will not change during the loop!
    Try this:
    Code:
    	while (document.test.Selectbox.childNodes.length > 0) {
    		document.test.Selectbox.removeChild(document.test.Selectbox.childNodes[0])
    	}
    Hope this helps,
    Jeroen
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    NL
    Posts
    19
    Rep Power
    0

    thnx


    thnx works like a charm..

    bedankt
    Met zo'n naam moet je dit haast wel kunnen lezen.

IMN logo majestic logo threadwatch logo seochat tools logo