| Terry Young on Jun 16, 2001 at 11:06:20 AM (# 1) Demo Add | Delete
Sample Code <a href="javascript:void(0)" onclick="if(document.all){ ouch.length++; ouch[ouch.length-1].innerText = ouch.length}; return false">Add</a> <a href="javascript:void(0)" onclick="if(document.all){ if(ouch.length>0){ ouch.length--;}}; return false">Delete</a> <select id="ouch" size="5" style="width: 120"></select>
Note Delete size="5" to get a drop down combo box...
Terry Young on Jun 16, 2001 at 11:27:07 AM (# 2)Version 2
| Add | Delete | Delete All | | Increase size | Decrease size | Set as dropdown list | Set to default size |
Note Have fun !! vinny on Jun 16, 2001 at 11:44:42 AM (# 3)Thanks a lot Terry.... poi on Jun 17, 2001 at 12:22:41 AM (# 4)Terry: your code is ok, but it only works in IE :( here is a cross browser version:
function removeOption( selectHandle, optionIndex ) { if( optionIndex<0 || optionIndex>=selectHandle.length ) return false selectHandle.option[ optionIndex ] = null return true }
function appendOption( selectHandle, optionText, optionValue ) { selectHandle.option[ selectHandle.length ] = new Option( optionText, optionValue ) return true }
and to get the selectHandle from a form element, you simply have to put: this.form.desiredSelectId
Cheers, Mathieu "POĻ" HENRI
|