Faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 35 people (34%) answered Yes
Recently 4 of 10 people (40%) answered Yes


how can remove element in dropdown list using java script

Aug 24th, 2008 15:38
Abolfazl Shirazi, ha mo, Jeff Papineau, Ankur Patel,

function removeLastOption() {
   var pulld = document.form1.pulldown;
   var leng = pulld.options.length;
   pulld.options[leng-1] = null;
<form name="form1">
    <select name="pulldown">
        <option value="">choose one...
        <option value="2">Mick
        <option value="37">Sean
        <option value="9">Chris
        <option value="1">Mark
    <button onClick="removeLastOption()"> Remove Last Option </button>
Abolfazl Shirazi:
you should set formName.options['Specific List Index Number']=null in 
order to remove element in dropdown list.
try the page below:
<script language="javascript">
function RemoveFrom() {
	if (myform.mylist.selectedIndex != -1) {
	myform.mylist.options[myform.mylist.selectedIndex] = null
<form name="myform">
<select name="mylist" size=11>
<option value="Pen Value">My Pen
<option value="Pencil Value">My Pencil
<option value="Bag Value">My Bag
<option value="Book Value">My Book
<option value="Note Value">My Note
<option value="Paper Value">My Paper
<option value="Table Value">My Table
<option value="Computer Value">My Computer
<option value="Documents Value">My Documents
<input type="button" value="Remove Selected Item"