Results 1 to 6 of 6

Thread: Clearing ListBoxes

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    39
    I have a multiple select list box that is enabled and disabled by a Checkbox, what I want to be able to do is clear out an pre-selected items after the box has been disabled. At the minute when I re-enable the box the prevoiusly selected items are still showing as being selected.

    The code I'm trying to use is.
    <input type="checkbox" name="chk1" value="chk1" onClick="if (chk1.checked) document.frmMethods.EG.disabled=true; else document.frmMethods.EG.disabled=false; ">

    <select name="EG" size="4" multiple onChange="if (EG.disabled) EG.selectedIndex=0;">

    Thanks

  2. #2
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Check out my response in this thread.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    39
    Invalid thread!

  4. #4
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Wierd.. I copied and pasted it right from the URL line.. it looks like the entire thread got deleted...

    I'll dig up my code and repost it for ya...
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  5. #5
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Ok.. first off, I'm unclear whether you really want to 'clear' the listbox or just un-select the selected items so I'll post both:

    Code:
    //Remove all items from a listbox
    //Javascript
    var colOptions = frmMyForm.lstMyList.options;
    var intList;
    		
    for (intList=colOptions .length-1; intList > -1; intList--)
    	colOptions .remove(intList);
    '-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
    'VBScript
    Dim colOptions
    Dim intList
    	
    Set colOptions = frmMyForm.lstMyList.options
    	
    For intList=colOptions.length-1 to 0 Step -1
    	colOptions.remove(intList)
    Next
    
    Set colOptions = Nothing
    '-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
    //Javascript
    //Unselect any selected Items
    var colOptions = frmMyForm.lstMyList.options;
    var intList;
    		
    for (intList=0;intList<colOptions .length; intList++)
    	if (colOptions[intList].selected)
    		colOptions[intList].selected=false;
    '-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
    'VBScript
    Dim colOptions
    Dim intList
    	
    Set colOptions = frmMyForm.lstMyList.options
    	
    For intList=0 to colOptions.length
    	If colOptions(intList).selected Then
    		colOptions(intList).selected=False
    	End If
    Next
    
    Set colOptions = Nothing
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    39
    Thank-you, I wanted to unselect the items.

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