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?

8 of 15 people (53%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

how can remove element in dropdown list using java script

Aug 24th, 2008 15:35
Abolfazl Shirazi, Ankur Patel,


**********************
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>

**********************