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

Entry

how can remove element in dropdown list using java script

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


<SCRIPT LANGUAGE="JavaScript">
function removeLastOption() {
   var pulld = document.form1.pulldown;
   var leng = pulld.options.length;
   pulld.options[leng-1] = null;
}
</SCRIPT>
<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
    </select>
    <button onClick="removeLastOption()"> Remove Last Option </button>
</form>
**********************
Abolfazl Shirazi:
you should set formName.options['Specific List Index Number']=null in 
order to remove element in dropdown list.
try the page below:
<html>
<head>
<script language="javascript">
function RemoveFrom() {
	if (myform.mylist.selectedIndex != -1) {
	myform.mylist.options[myform.mylist.selectedIndex] = null
	}
}
</script>
</head>
<body>
<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
</select><p>
<input type="button" value="Remove Selected Item"
onclick="RemoveFrom
()">
</body>
</html>
**********************