SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : Dynamic HTML :

Previous DiscussionNext Discussion
 Dynamic Select box

How to add and delete new Options to an existing Select box or a dropdown list..

Thanx to all.

Started By vinny on Jun 16, 2001 at 10:26:57 AM

4 Response(s) | Reply

Earlier Replies | Replies 1 to 4 of 4 | Later Replies
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


Earlier Replies | Replies 1 to 4 of 4 | Later Replies

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.